DR 1155
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 18 Aug 2015 21:29:01 +0000 (21:29 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 18 Aug 2015 21:29:01 +0000 (21:29 +0000)
* pt.c (convert_nontype_argument): Allow internal linkage in C++11
and up.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@226992 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/nontype1.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.oliva/template4.C

index 0bf33c8..2c2cb6d 100644 (file)
@@ -1,3 +1,9 @@
+2015-08-18  Jason Merrill  <jason@redhat.com>
+
+       DR 1155
+       * pt.c (convert_nontype_argument): Allow internal linkage in C++11
+       and up.
+
 2015-08-17  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/67216
index b84bda4..eaafaef 100644 (file)
@@ -6469,16 +6469,18 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
        {
          if (complain & tf_error)
            error ("%qE is not a valid template argument for type %qT "
-                  "because it is not an object with external linkage",
+                  "because it is not an object with linkage",
                   expr, type);
          return NULL_TREE;
        }
 
-      if (!DECL_EXTERNAL_LINKAGE_P (expr))
+      /* DR 1155 allows internal linkage in C++11 and up.  */
+      linkage_kind linkage = decl_linkage (expr);
+      if (linkage < (cxx_dialect >= cxx11 ? lk_internal : lk_external))
        {
          if (complain & tf_error)
            error ("%qE is not a valid template argument for type %qT "
-                  "because object %qD has not external linkage",
+                  "because object %qD does not have linkage",
                   expr, type, expr);
          return NULL_TREE;
        }
diff --git a/gcc/testsuite/g++.dg/cpp0x/nontype1.C b/gcc/testsuite/g++.dg/cpp0x/nontype1.C
new file mode 100644 (file)
index 0000000..29dff36
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++11 } }
+
+struct L { constexpr operator int() const { return 0; } };
+constexpr L LVar{};
+
+template<const L&> int *f() { return 0; }
+template<int> char *f();
+
+auto r = f<LVar>();            // { dg-error "ambiguous" }
index 2268fde..ef607f6 100644 (file)
@@ -11,7 +11,7 @@ int a = 1;
 X<a> x; // ok, a has external linkage
 
 const int b = 2;
-X<b> y; // { dg-error "" } const b has internal linkage
+X<b> y; // { dg-error "" "" { target c++98_only } } const b has internal linkage
 
 extern const int c;
 X<c> z; // ok, c has external linkage