Comments
Patch
@@ -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);
+ }
}
}
new file mode 100644
@@ -0,0 +1,10 @@
+// PR c++/47705
+
+template<char const * const x> class Something {
+};
+
+extern char const xyz;
+
+class SomethingElse:public Something<xyz> { // { dg-error "const char *" }
+};
+
We were asserting that any argument to a non-type template parameter of pointer type must be an address. Which is true of valid code (apart from null pointer values), but not necessarily of invalid code, where we should complain rather than crash. Tested x86_64-pc-linux-gnu, applied to trunk. commit 0aa8b389e5b3d863edd4e9969cadf2af5f2c1907 Author: Jason Merrill <jason@redhat.com> Date: Tue Mar 8 11:02:49 2011 -0500 PR c++/47705 * pt.c (convert_nontype_argument): Don't crash on non-pointer argument to pointer parameter.