aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2016-06-28 20:09:36 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2016-06-28 14:09:36 -0600
commit4378d117ec35f58d5a552eafcb91c91550e6566e (patch)
tree0e59ed1bcb50dd34df30c681054cb932f229267f /gcc/c
parentd41dc215ce9eaf812562b1858e5f098e0de82d5e (diff)
downloadgcc-4378d117ec35f58d5a552eafcb91c91550e6566e.zip
gcc-4378d117ec35f58d5a552eafcb91c91550e6566e.tar.gz
gcc-4378d117ec35f58d5a552eafcb91c91550e6566e.tar.bz2
PR c/71552 - Confusing error for incorrect struct initialization
gcc/c/ChangeLog: PR c/71552 * c-typeck.c (output_init_element): Diagnose incompatible types before non-constant initializers. gcc/testsuite/ChangeLog: PR c/71552 * gcc.dg/init-bad-9.c: New test. From-SVN: r237829
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-typeck.c29
2 files changed, 24 insertions, 11 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index d32049c..403f267 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2016-06-28 Martin Sebor <msebor@redhat.com>
+
+ PR c/71552
+ * c-typeck.c (output_init_element): Diagnose incompatible types
+ before non-constant initializers.
+
2016-06-28 Jakub Jelinek <jakub@redhat.com>
* Make-lang.in: Don't cat ../stage_current if it does not exist.
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 7c6241c..818ad94 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -8754,6 +8754,22 @@ output_init_element (location_t loc, tree value, tree origtype,
if (!maybe_const)
constructor_nonconst = 1;
+ /* Digest the initializer and issue any errors about incompatible
+ types before issuing errors about non-constant initializers. */
+ tree new_value = value;
+ if (semantic_type)
+ new_value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
+ new_value = digest_init (loc, type, new_value, origtype, npc, strict_string,
+ require_constant_value);
+ if (new_value == error_mark_node)
+ {
+ constructor_erroneous = 1;
+ return;
+ }
+ if (require_constant_value || require_constant_elements)
+ constant_expression_warning (new_value);
+
+ /* Proceed to check the constness of the original initializer. */
if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
{
if (require_constant_value)
@@ -8798,17 +8814,8 @@ output_init_element (location_t loc, tree value, tree origtype,
|| DECL_CHAIN (field)))))
return;
- if (semantic_type)
- value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
- value = digest_init (loc, type, value, origtype, npc, strict_string,
- require_constant_value);
- if (value == error_mark_node)
- {
- constructor_erroneous = 1;
- return;
- }
- if (require_constant_value || require_constant_elements)
- constant_expression_warning (value);
+ /* Finally, set VALUE to the initializer value digested above. */
+ value = new_value;
/* If this element doesn't come next in sequence,
put it on constructor_pending_elts. */