diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2004-12-21 17:54:25 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2004-12-21 17:54:25 +0000 |
commit | 7a8380aebb80b0f567b218204d6e926105b9d305 (patch) | |
tree | f5295c69fc8f09f127b9123926fef7ac163cb383 /gcc | |
parent | 38b3627d6fcedf4e1b99e988440c1c366f6dba10 (diff) | |
download | gcc-7a8380aebb80b0f567b218204d6e926105b9d305.zip gcc-7a8380aebb80b0f567b218204d6e926105b9d305.tar.gz gcc-7a8380aebb80b0f567b218204d6e926105b9d305.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 7 | ||||
-rw-r--r-- | gcc/cp/decl.c | 6 | ||||
-rw-r--r-- | gcc/cp/error.c | 9 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 3 |
6 files changed, 35 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c90f5af..b0c25a7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 82cd13f..c6d47c9 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -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) \ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index dbaf23e..515bb2c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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; } } diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 8599616..ec332f2 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -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; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 19c6d5d..ab1c028 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2633376..640674a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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. |