re PR c++/47705 (internal compiler error: in convert_nontype_argument, at cp/pt.c...
authorJason Merrill <jason@redhat.com>
Tue, 8 Mar 2011 17:30:36 +0000 (12:30 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 8 Mar 2011 17:30:36 +0000 (12:30 -0500)
PR c++/47705
* pt.c (convert_nontype_argument): Don't crash on non-pointer
argument to pointer parameter.

From-SVN: r170782

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/nontype21.C [new file with mode: 0644]

index 319bdf3d7a35997dc26a966f118cddf919210ddf..e99a53a67c33ad6df62be91c26ed2102c4420259 100644 (file)
@@ -1,5 +1,9 @@
 2011-03-08  Jason Merrill  <jason@redhat.com>
 
+       PR c++/47705
+       * pt.c (convert_nontype_argument): Don't crash on non-pointer
+       argument to pointer parameter.
+
        PR c++/45651
        * pt.c (instantiate_decl): Don't clear DECL_INTERFACE_KNOWN on
        !TREE_PUBLIC decls.
index 48f938222747744e6f4a884b4061243fd8713fd5..cda9df8d1be5f9cc159cfc93c2b6c39bcd189c5a 100644 (file)
@@ -5369,15 +5369,20 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
         qualification conversion. Let's strip everything.  */
       else if (TYPE_PTROBV_P (type))
        {
-         STRIP_NOPS (expr);
-         gcc_assert (TREE_CODE (expr) == ADDR_EXPR);
-         gcc_assert (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE);
-         /* Skip the ADDR_EXPR only if it is part of the decay for
-            an array. Otherwise, it is part of the original argument
-            in the source code.  */
-         if (TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == ARRAY_TYPE)
-           expr = TREE_OPERAND (expr, 0);
-         expr_type = TREE_TYPE (expr);
+         tree sub = expr;
+         STRIP_NOPS (sub);
+         if (TREE_CODE (sub) == ADDR_EXPR)
+           {
+             gcc_assert (TREE_CODE (TREE_TYPE (sub)) == POINTER_TYPE);
+             /* Skip the ADDR_EXPR only if it is part of the decay for
+                an array. Otherwise, it is part of the original argument
+                in the source code.  */
+             if (TREE_CODE (TREE_TYPE (TREE_OPERAND (sub, 0))) == ARRAY_TYPE)
+               expr = TREE_OPERAND (sub, 0);
+             else
+               expr = sub;
+             expr_type = TREE_TYPE (expr);
+           }
        }
     }
 
index 28caa917a7240ee52cb14bb9171a0f4903e193d7..bfc0e9d2e1b3524094de5ab0be866eb0650006c2 100644 (file)
@@ -1,5 +1,7 @@
 2011-03-08  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/template/nontype21.C: New.
+
        * g++.dg/template/anon5.C: New.
 
 2011-03-08  Jakub Jelinek  <jakub@redhat.com>
diff --git a/gcc/testsuite/g++.dg/template/nontype21.C b/gcc/testsuite/g++.dg/template/nontype21.C
new file mode 100644 (file)
index 0000000..c0f5319
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/47705
+
+template<char const * const x> class Something { };
+
+extern char const xyz;
+
+class SomethingElse:public Something<xyz> { }; // { dg-error "const char *" }