aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-typeck.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2010-05-09 21:39:39 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2010-05-09 21:39:39 +0100
commit0fb96aa42870c811a3c38feebb1d25786bca30e2 (patch)
treee7b85702c307070dfea9f600d40c327566bda8aa /gcc/c-typeck.c
parent3d7a712a1e3b2e67b5261e8e4b34f3b701f49a70 (diff)
downloadgcc-0fb96aa42870c811a3c38feebb1d25786bca30e2.zip
gcc-0fb96aa42870c811a3c38feebb1d25786bca30e2.tar.gz
gcc-0fb96aa42870c811a3c38feebb1d25786bca30e2.tar.bz2
re PR c/10676 (Using unnamed fields in initializers)
PR c/10676 * c-typeck.c (lookup_field): Take a type directly. Update recursive calls. (build_component_ref): Update call to lookup_field. (set_init_label): Use lookup_field to find initialized field. Handle returned list of fields like a sequence of designators. testsuite: * gcc.dg/anon-struct-10.c: New test. From-SVN: r159206
Diffstat (limited to 'gcc/c-typeck.c')
-rw-r--r--gcc/c-typeck.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 2f66d6a..1bac4fd 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -1953,7 +1953,7 @@ default_conversion (tree exp)
return exp;
}
-/* Look up COMPONENT in a structure or union DECL.
+/* Look up COMPONENT in a structure or union TYPE.
If the component name is not found, returns NULL_TREE. Otherwise,
the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
@@ -1963,9 +1963,8 @@ default_conversion (tree exp)
unions, the list steps down the chain to the component. */
static tree
-lookup_field (tree decl, tree component)
+lookup_field (tree type, tree component)
{
- tree type = TREE_TYPE (decl);
tree field;
/* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
@@ -1995,7 +1994,7 @@ lookup_field (tree decl, tree component)
if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
|| TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
{
- tree anon = lookup_field (field, component);
+ tree anon = lookup_field (TREE_TYPE (field), component);
if (anon)
return tree_cons (NULL_TREE, field, anon);
@@ -2031,7 +2030,7 @@ lookup_field (tree decl, tree component)
&& (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
|| TREE_CODE (TREE_TYPE (field)) == UNION_TYPE))
{
- tree anon = lookup_field (field, component);
+ tree anon = lookup_field (TREE_TYPE (field), component);
if (anon)
return tree_cons (NULL_TREE, field, anon);
@@ -2074,7 +2073,7 @@ build_component_ref (location_t loc, tree datum, tree component)
return error_mark_node;
}
- field = lookup_field (datum, component);
+ field = lookup_field (type, component);
if (!field)
{
@@ -6983,7 +6982,7 @@ set_init_index (tree first, tree last,
void
set_init_label (tree fieldname, struct obstack * braced_init_obstack)
{
- tree tail;
+ tree field;
if (set_designator (0, braced_init_obstack))
return;
@@ -6997,23 +6996,26 @@ set_init_label (tree fieldname, struct obstack * braced_init_obstack)
return;
}
- for (tail = TYPE_FIELDS (constructor_type); tail;
- tail = TREE_CHAIN (tail))
- {
- if (DECL_NAME (tail) == fieldname)
- break;
- }
+ field = lookup_field (constructor_type, fieldname);
- if (tail == 0)
+ if (field == 0)
error ("unknown field %qE specified in initializer", fieldname);
else
- {
- constructor_fields = tail;
- designator_depth++;
- designator_erroneous = 0;
- if (constructor_range_stack)
- push_range_stack (NULL_TREE, braced_init_obstack);
- }
+ do
+ {
+ constructor_fields = TREE_VALUE (field);
+ designator_depth++;
+ designator_erroneous = 0;
+ if (constructor_range_stack)
+ push_range_stack (NULL_TREE, braced_init_obstack);
+ field = TREE_CHAIN (field);
+ if (field)
+ {
+ if (set_designator (0, braced_init_obstack))
+ return;
+ }
+ }
+ while (field != NULL_TREE);
}
/* Add a new initializer to the tree of pending initializers. PURPOSE