for gcc/ChangeLog from Alexandre Oliva * c-typeck.c (tagged_types_tu_compatible_p): Enable exact matches between anonymous union fields. --- gcc-4.1.0/gcc/c-typeck.c.pr27898~ 2006-05-03 14:35:48.000000000 +0100 +++ gcc-4.1.0/gcc/c-typeck.c 2006-08-12 14:47:46.000000000 +0100 @@ -1052,11 +1052,12 @@ tagged_types_tu_compatible_Cp (tree t1, t { int result; - - if (DECL_NAME (s1) == NULL - || DECL_NAME (s1) != DECL_NAME (s2)) + if (DECL_NAME (s1) != DECL_NAME (s2)) break; result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2)); + + if (result != 1 && !DECL_NAME (s1)) + break; if (result == 0) { tu->val = 0; @@ -1083,28 +1084,31 @@ tagged_types_tu_compatible_p (tree t1, t { bool ok = false; - if (DECL_NAME (s1) != NULL) - for (s2 = TYPE_FIELDS (t2); s2; s2 = TREE_CHAIN (s2)) - if (DECL_NAME (s1) == DECL_NAME (s2)) - { - int result; - result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2)); - if (result == 0) - { - tu->val = 0; - return 0; - } - if (result == 2) - needs_warning = true; - - if (TREE_CODE (s1) == FIELD_DECL - && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), - DECL_FIELD_BIT_OFFSET (s2)) != 1) - break; + for (s2 = TYPE_FIELDS (t2); s2; s2 = TREE_CHAIN (s2)) + if (DECL_NAME (s1) == DECL_NAME (s2)) + { + int result; + + result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2)); - ok = true; + if (result != 1 && !DECL_NAME (s1)) + continue; + if (result == 0) + { + tu->val = 0; + return 0; + } + if (result == 2) + needs_warning = true; + + if (TREE_CODE (s1) == FIELD_DECL + && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), + DECL_FIELD_BIT_OFFSET (s2)) != 1) break; - } + + ok = true; + break; + } if (!ok) { tu->val = 0;