From: Jakub Jelinek Date: Sun, 5 Jan 2020 12:50:40 +0000 (+0100) Subject: re PR c++/93138 (elaborated type specifier visibility check problem) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=39bec8cd35fa035aa10ddb123eb8a5715d323457;p=gcc.git re PR c++/93138 (elaborated type specifier visibility check problem) PR c++/93138 * parser.c (cp_parser_check_class_key): Disable access checks for the simple name lookup. (cp_parser_maybe_warn_enum_key): Likewise. Return early if !warn_redundant_tags. * g++.dg/warn/Wredundant-tags-2.C: New test. From-SVN: r279886 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a1fb787e555..3e5f58cac2a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2020-01-05 Jakub Jelinek + + PR c++/93138 + * parser.c (cp_parser_check_class_key): Disable access checks for the + simple name lookup. + (cp_parser_maybe_warn_enum_key): Likewise. Return early if + !warn_redundant_tags. + 2010-01-05 Jakub Jelinek PR c++/93046 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a637a289a1a..7cd8e150dd5 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -30663,11 +30663,15 @@ static void cp_parser_maybe_warn_enum_key (cp_parser *parser, location_t key_loc, tree type, rid scoped_key) { + if (!warn_redundant_tags) + return; + tree type_decl = TYPE_MAIN_DECL (type); tree name = DECL_NAME (type_decl); - /* Look up the NAME to see if it unambiguously refers to the TYPE - and set KEY_REDUNDANT if so. */ + /* Look up the NAME to see if it unambiguously refers to the TYPE. */ + push_deferring_access_checks (dk_no_check); tree decl = cp_parser_lookup_name_simple (parser, name, input_location); + pop_deferring_access_checks (); /* The enum-key is redundant for uses of the TYPE that are not declarations and for which name lookup returns just the type @@ -30837,7 +30841,9 @@ cp_parser_check_class_key (cp_parser *parser, location_t key_loc, tree name = DECL_NAME (type_decl); /* Look up the NAME to see if it unambiguously refers to the TYPE and set KEY_REDUNDANT if so. */ + push_deferring_access_checks (dk_no_check); tree decl = cp_parser_lookup_name_simple (parser, name, input_location); + pop_deferring_access_checks (); /* The class-key is redundant for uses of the CLASS_TYPE that are neither definitions of it nor declarations, and for which name diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4581c9f6c27..c3f541b7c5d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,7 @@ -2010-01-05 Jakub Jelinek +2020-01-05 Jakub Jelinek + + PR c++/93138 + * g++.dg/warn/Wredundant-tags-2.C: New test. PR c++/93046 * g++.dg/ext/cond4.C: New test. diff --git a/gcc/testsuite/g++.dg/warn/Wredundant-tags-2.C b/gcc/testsuite/g++.dg/warn/Wredundant-tags-2.C new file mode 100644 index 00000000000..aee4963464b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wredundant-tags-2.C @@ -0,0 +1,18 @@ +// PR c++/93138 +// { dg-do compile } +// { dg-options "-Wredundant-tags" } + +struct Foo +{ + enum Kind { a }; +private: + Kind Kind; +}; +enum Foo::Kind foo (); // { dg-bogus "is private within this context|redundant" } +struct Bar +{ + struct Kind { int a; }; +private: + Kind Kind; +}; +struct Bar::Kind bar (); // { dg-bogus "is private within this context|redundant" }