Patchwork C++ PATCH for c++/36797 (use of __is_empty in template signature)

login
register
mail settings
Submitter Jason Merrill
Date March 4, 2012, 12:55 a.m.
Message ID <4F52BD9F.1020801@redhat.com>
Download mbox | patch
Permalink /patch/144474/
State New
Headers show

Comments

Jason Merrill - March 4, 2012, 12:55 a.m.
Since we've decided not to mangle __is_empty and such, this patch 
provides a more helpful error message.

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

Patch

commit bdaa797823a9e45261cfe7a97e4f568decba790b
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jan 12 12:42:07 2012 -0500

    	PR c++/36797
    	* mangle.c (write_expression): Improve diagnostic for TRAIT_EXPR.

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 34f19ef..04f4344 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -2808,7 +2808,17 @@  write_expression (tree expr)
 
       if (name == NULL)
 	{
-	  sorry ("mangling %C", code);
+	  switch (code)
+	    {
+	    case TRAIT_EXPR:
+	      error ("use of built-in trait %qE in function signature; "
+		     "use library traits instead", expr);
+	      break;
+
+	    default:
+	      sorry ("mangling %C", code);
+	      break;
+	    }
 	  return;
 	}
       else
diff --git a/gcc/testsuite/g++.dg/ext/is_empty2.C b/gcc/testsuite/g++.dg/ext/is_empty2.C
new file mode 100644
index 0000000..d1bf64c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_empty2.C
@@ -0,0 +1,11 @@ 
+// PR c++/36797
+
+template <int> struct A { };
+
+template <class T>
+int foo (A<__is_empty (T)>* = 0); // { dg-error "built-in trait" }
+
+int main ()
+{
+    foo<int>();
+}