public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for DR 1155 (template arguments with internal linkage)
@ 2015-08-18 21:26 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2015-08-18 21:26 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 178 bytes --]

My patch for bug 50372 implemented DR 1155 for arguments of pointer 
type, but neglected to implement it for reference arguments.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: dr1155.patch --]
[-- Type: text/x-patch, Size: 2166 bytes --]

commit 6fe0feb89daa09ff32709ca10734f8063a26f6e9
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Aug 17 15:18:03 2015 -0400

    	DR 1155
    	* pt.c (convert_nontype_argument): Allow internal linkage in C++11
    	and up.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b84bda4..eaafaef 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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
index 0000000..29dff363
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nontype1.C
@@ -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" }
diff --git a/gcc/testsuite/g++.old-deja/g++.oliva/template4.C b/gcc/testsuite/g++.old-deja/g++.oliva/template4.C
index 2268fde..ef607f6 100644
--- a/gcc/testsuite/g++.old-deja/g++.oliva/template4.C
+++ b/gcc/testsuite/g++.old-deja/g++.oliva/template4.C
@@ -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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-18 21:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-18 21:26 C++ PATCH for DR 1155 (template arguments with internal linkage) Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).