From: Nathan Sidwell Date: Tue, 20 Mar 2018 16:01:08 +0000 (+0000) Subject: [PR c++/84962] ICE with anon-struct member X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6f87580f7d0726d9683ca0f4a703a857f06f00d5;p=gcc.git [PR c++/84962] ICE with anon-struct member https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00961.html PR c++/84962 * name-lookup.c (pushdecl_class_level): Push anon-struct's member_vec, if there is one. PR c++/84962 * g++.dg/lookup/pr84962.C: New. From-SVN: r258686 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7ce79d3862b..5d7b9c09983 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2018-03-20 Nathan Sidwell + PR c++/84962 + * name-lookup.c (pushdecl_class_level): Push anon-struct's + member_vec, if there is one. + PR c++/84970 * cp-tree.h (lookup_list_keep): Declare. * tree.c (lookup_list_keep): New, broken out of ... diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index cc8bb2f81c6..411a79696a1 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -4490,16 +4490,30 @@ pushdecl_class_level (tree x) /* If X is an anonymous aggregate, all of its members are treated as if they were members of the class containing the aggregate, for naming purposes. */ - tree f; - - for (f = TYPE_FIELDS (TREE_TYPE (x)); f; f = DECL_CHAIN (f)) - { - location_t save_location = input_location; - input_location = DECL_SOURCE_LOCATION (f); - if (!pushdecl_class_level (f)) - is_valid = false; - input_location = save_location; + location_t save_location = input_location; + tree anon = TREE_TYPE (x); + if (vec *member_vec = CLASSTYPE_MEMBER_VEC (anon)) + for (unsigned ix = member_vec->length (); ix--;) + { + tree binding = (*member_vec)[ix]; + if (STAT_HACK_P (binding)) + { + if (!pushdecl_class_level (STAT_TYPE (binding))) + is_valid = false; + binding = STAT_DECL (binding); + } + if (!pushdecl_class_level (binding)) + is_valid = false; } + else + for (tree f = TYPE_FIELDS (anon); f; f = DECL_CHAIN (f)) + if (TREE_CODE (f) == FIELD_DECL) + { + input_location = DECL_SOURCE_LOCATION (f); + if (!pushdecl_class_level (f)) + is_valid = false; + } + input_location = save_location; } timevar_cond_stop (TV_NAME_LOOKUP, subtime); return is_valid; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 14c775ba191..21a16df4884 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-03-20 Nathan Sidwell + PR c++/84962 + * g++.dg/lookup/pr84962.C: New. + PR c++/84970 * g++.dg/lookup/pr84970.C: New. diff --git a/gcc/testsuite/g++.dg/lookup/pr84962.C b/gcc/testsuite/g++.dg/lookup/pr84962.C new file mode 100644 index 00000000000..ee801c247bc --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/pr84962.C @@ -0,0 +1,14 @@ +// PR c++/84952 ICE with anon-struct having member fns +// { dg-do compile { target c++11 } } +// { dg-additional-options -Wno-pedantic } + +struct X { + struct + { + template int a (); + // { dg-error "can only have" "" { target *-*-* } .-1 } + }; + + int : a; // { dg-error "non-integral" } +}; +