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.
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).
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) \
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;
}
}
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;
/* [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;
}
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.