Commit cb3c050e by Jason Merrill Committed by Jason Merrill

re PR c++/54946 (ICE on template parameter from cast char-pointer in C++11 constexpr struct)

	PR c++/54946
	* pt.c (convert_nontype_argument): Handle invalid pointer.

From-SVN: r196731
parent e9f3968b
2013-03-16 Jason Merrill <jason@redhat.com> 2013-03-16 Jason Merrill <jason@redhat.com>
PR c++/54946
* pt.c (convert_nontype_argument): Handle invalid pointer.
* parser.c (cp_parser_lambda_expression): Use nreverse. * parser.c (cp_parser_lambda_expression): Use nreverse.
PR c++/56447 PR c++/56447
......
...@@ -5553,16 +5553,20 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) ...@@ -5553,16 +5553,20 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
qualification conversion. Let's strip everything. */ qualification conversion. Let's strip everything. */
else if (TREE_CODE (expr) == NOP_EXPR && TYPE_PTROBV_P (type)) else if (TREE_CODE (expr) == NOP_EXPR && TYPE_PTROBV_P (type))
{ {
STRIP_NOPS (expr); tree probe = expr;
gcc_assert (TREE_CODE (expr) == ADDR_EXPR); STRIP_NOPS (probe);
gcc_assert (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE); if (TREE_CODE (probe) == ADDR_EXPR
&& TREE_CODE (TREE_TYPE (probe)) == POINTER_TYPE)
{
/* Skip the ADDR_EXPR only if it is part of the decay for /* Skip the ADDR_EXPR only if it is part of the decay for
an array. Otherwise, it is part of the original argument an array. Otherwise, it is part of the original argument
in the source code. */ in the source code. */
if (TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == ARRAY_TYPE) if (TREE_CODE (TREE_TYPE (TREE_OPERAND (probe, 0))) == ARRAY_TYPE)
expr = TREE_OPERAND (expr, 0); probe = TREE_OPERAND (probe, 0);
expr = probe;
expr_type = TREE_TYPE (expr); expr_type = TREE_TYPE (expr);
} }
}
/* [temp.arg.nontype]/5, bullet 1 /* [temp.arg.nontype]/5, bullet 1
...@@ -5640,6 +5644,13 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) ...@@ -5640,6 +5644,13 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
expr, expr); expr, expr);
return NULL_TREE; return NULL_TREE;
} }
if (POINTER_TYPE_P (expr_type))
{
error ("%qE is not a valid template argument for %qT"
"because it is not the address of a variable",
expr, type);
return NULL_TREE;
}
/* Other values, like integer constants, might be valid /* Other values, like integer constants, might be valid
non-type arguments of some other type. */ non-type arguments of some other type. */
return error_mark_node; return error_mark_node;
......
// PR c++/54946
// { dg-do compile { target c++11 } }
template<const char*s> static void testfunc();
constexpr struct testtype { const char* str; } test = { "abc"} ;
void (*functionpointer)() = testfunc<(const char*) test.str>; // { dg-error "" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment