aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Wilson <wilson@gcc.gnu.org>1993-09-14 19:03:22 -0700
committerJim Wilson <wilson@gcc.gnu.org>1993-09-14 19:03:22 -0700
commitd9fc6069c69564ce7fecd9ca0ce1bbe0b3c130ef (patch)
treeda37e4404423e54044b0d16536a0cc4b463ec6a1
parent179bb78c239573cbd4ea5b8577c56ba9b755183f (diff)
downloadgcc-d9fc6069c69564ce7fecd9ca0ce1bbe0b3c130ef.zip
gcc-d9fc6069c69564ce7fecd9ca0ce1bbe0b3c130ef.tar.gz
gcc-d9fc6069c69564ce7fecd9ca0ce1bbe0b3c130ef.tar.bz2
(valid_compound_expr_initializer): New function.
(digest_init): Handle compound expressions as initializers when pedantic. From-SVN: r5323
-rw-r--r--gcc/c-typeck.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 7862221..3dd7288 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -4579,6 +4579,32 @@ initializer_constant_valid_p (value, endtype)
return 0;
}
+
+/* If VALUE is a compound expr all of whose expressions are constant, then
+ return its value. Otherwise, return error_mark_node.
+
+ This is for handling COMPOUND_EXPRs as initializer elements
+ which is allowed with a warning when -pedantic is specified. */
+
+static tree
+valid_compound_expr_initializer (value, endtype)
+ tree value;
+ tree endtype;
+{
+ if (TREE_CODE (value) == COMPOUND_EXPR)
+ {
+ if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
+ == error_mark_node)
+ return error_mark_node;
+ return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
+ endtype);
+ }
+ else if (! TREE_CONSTANT (value)
+ && ! initializer_constant_valid_p (value, endtype))
+ return error_mark_node;
+ else
+ return value;
+}
/* Perform appropriate conversions on the initial value of a variable,
store it in the declaration DECL,
@@ -4969,7 +4995,25 @@ digest_init (type, init, require_constant, constructor_constant)
&& TREE_CODE (inside_init) == VAR_DECL)
inside_init = decl_constant_value (inside_init);
- if (require_constant && ! TREE_CONSTANT (inside_init))
+ /* Compound expressions can only occur here if -pedantic or
+ -pedantic-errors is specified. In the later case, we always want
+ an error. In the former case, we simply want a warning. */
+ if (require_constant && pedantic
+ && TREE_CODE (inside_init) == COMPOUND_EXPR)
+ {
+ inside_init
+ = valid_compound_expr_initializer (inside_init,
+ TREE_TYPE (inside_init));
+ if (inside_init == error_mark_node)
+ error_init ("initializer element%s is not constant",
+ " for `%s'", NULL);
+ else
+ pedwarn_init ("initializer element%s is not constant",
+ " for `%s'", NULL);
+ if (flag_pedantic_errors)
+ inside_init = error_mark_node;
+ }
+ else if (require_constant && ! TREE_CONSTANT (inside_init))
{
error_init ("initializer element%s is not constant",
" for `%s'", NULL);