re PR c++/14075 (("foo") accepted as char[] initializer)
cp: PR c++/14075 * decl.c (check_initializer): Check string initializer of array is not parenthesized. * cp-tree.h (PAREN_STRING_LITERAL_P): New. * semantics.c (finish_parenthesized_expr): Mark a STRING_CST. * error.c (dump_expr): <STRING_CST case> Add parens, if needed. testsuite: PR c++/14075 * g++.dg/init/string1.C: New. From-SVN: r92464
This commit is contained in:
parent
38b3627d6f
commit
7a8380aebb
|
@ -1,5 +1,12 @@
|
|||
2004-12-21 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
PR c++/14075
|
||||
* decl.c (check_initializer): Check string initializer of array is
|
||||
not parenthesized.
|
||||
* cp-tree.h (PAREN_STRING_LITERAL_P): New.
|
||||
* semantics.c (finish_parenthesized_expr): Mark a STRING_CST.
|
||||
* error.c (dump_expr): <STRING_CST case> Add parens, if needed.
|
||||
|
||||
* cp-tree.def (TEMPLATE_TYPE_PARM,
|
||||
BOUND_TEMPLATE_TEMPLATE_PARM, TYPE_OF_TYPE, TYPENAME_TYPE): Reorder
|
||||
for better code efficiency.
|
||||
|
|
|
@ -42,6 +42,7 @@ struct diagnostic_context;
|
|||
CLEANUP_P (in TRY_BLOCK)
|
||||
AGGR_INIT_VIA_CTOR_P (in AGGR_INIT_EXPR)
|
||||
PTRMEM_OK_P (in ADDR_EXPR, OFFSET_REF)
|
||||
PAREN_STRING_LITERAL (in STRING_CST)
|
||||
DECL_PRETTY_FUNCTION_P (in VAR_DECL)
|
||||
KOENIG_LOOKUP_P (in CALL_EXPR)
|
||||
STATEMENT_LIST_NO_SCOPE (in STATEMENT_LIST).
|
||||
|
@ -2248,6 +2249,12 @@ struct lang_decl GTY(())
|
|||
should be performed at instantiation time. */
|
||||
#define KOENIG_LOOKUP_P(NODE) TREE_LANG_FLAG_0 (CALL_EXPR_CHECK (NODE))
|
||||
|
||||
/* Indicates whether a string literal has been parenthesized. Such
|
||||
usages are disallowed in certain circumstances. */
|
||||
|
||||
#define PAREN_STRING_LITERAL_P(NODE) \
|
||||
TREE_LANG_FLAG_0 (STRING_CST_CHECK (NODE))
|
||||
|
||||
/* Nonzero if this AGGR_INIT_EXPR provides for initialization via a
|
||||
constructor call, rather than an ordinary function call. */
|
||||
#define AGGR_INIT_VIA_CTOR_P(NODE) \
|
||||
|
|
|
@ -4596,6 +4596,12 @@ check_initializer (tree decl, tree init, int flags, tree *cleanup)
|
|||
if (TREE_CODE (init) != TREE_VEC)
|
||||
{
|
||||
init_code = store_init_value (decl, init);
|
||||
if (pedantic && TREE_CODE (type) == ARRAY_TYPE
|
||||
&& DECL_INITIAL (decl)
|
||||
&& TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
|
||||
&& PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
|
||||
warning ("array %qD initialized by parenthesized string literal %qE",
|
||||
decl, DECL_INITIAL (decl));
|
||||
init = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1286,8 +1286,15 @@ dump_expr (tree t, int flags)
|
|||
dump_decl (t, (flags & ~TFF_DECL_SPECIFIERS) | TFF_NO_FUNCTION_ARGUMENTS);
|
||||
break;
|
||||
|
||||
case INTEGER_CST:
|
||||
case STRING_CST:
|
||||
if (PAREN_STRING_LITERAL_P (t))
|
||||
pp_cxx_left_paren (cxx_pp);
|
||||
pp_c_constant (pp_c_base (cxx_pp), t);
|
||||
if (PAREN_STRING_LITERAL_P (t))
|
||||
pp_cxx_right_paren (cxx_pp);
|
||||
break;
|
||||
|
||||
case INTEGER_CST:
|
||||
case REAL_CST:
|
||||
pp_c_constant (pp_c_base (cxx_pp), t);
|
||||
break;
|
||||
|
|
|
@ -1272,6 +1272,10 @@ finish_parenthesized_expr (tree expr)
|
|||
/* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
|
||||
enclosed in parentheses. */
|
||||
PTRMEM_OK_P (expr) = 0;
|
||||
|
||||
if (TREE_CODE (expr) == STRING_CST)
|
||||
PAREN_STRING_LITERAL_P (expr) = 1;
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
2004-12-21 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
PR c++/14075
|
||||
* g++.dg/init/string1.C: New.
|
||||
|
||||
PR c++/18975
|
||||
* g++.dg/other/synth1.C: New.
|
||||
|
||||
|
|
Loading…
Reference in New Issue