diff options
author | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2019-02-14 23:02:45 +0000 |
---|---|---|
committer | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2019-02-14 23:02:45 +0000 |
commit | 2f6fdfb690b1e045d54f3198f3232dbe4c1eb4fc (patch) | |
tree | 95e8cc110e74bd49ea3afcb4b17969480fdedefa | |
parent | 948b609a846b2b622eb8bcac8850054781683b52 (diff) |
C++: don't offer bogus "._0" suggestions (PR c++/86329)
PR c++/86329 reports that the C++ frontend can offer bogus suggestions like:
#include <string>
int compare()
{
return __n1 - __n2;
}
suggested.cc: In function 'int compare()':
suggested.cc:5:10: error: '__n1' was not declared in this scope
return __n1 - __n2;
^~~~
suggested.cc:5:10: note: suggested alternative: '._61'
return __n1 - __n2;
^~~~
._61
suggested.cc:5:17: error: '__n2' was not declared in this scope
return __n1 - __n2;
^~~~
suggested.cc:5:17: note: suggested alternative: '._72'
return __n1 - __n2;
^~~~
._72
The dot-prefixed names are an implementation detail of how we implement
anonymous enums found in the header files, generated via
anon_aggrname_format in make_anon_name.
This patch uses anon_aggrname_p to filter them out when considering
which names to suggest.
gcc/cp/ChangeLog:
Backport of r262199 from trunk.
2018-06-27 David Malcolm <dmalcolm@redhat.com>
PR c++/86329
* name-lookup.c (consider_binding_level): Filter out names that
match anon_aggrname_p.
gcc/testsuite/ChangeLog:
Backport of r262199 from trunk.
2018-06-27 David Malcolm <dmalcolm@redhat.com>
PR c++/86329
* g++.dg/lookup/pr86329.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-8-branch@268909 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cp/name-lookup.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/lookup/pr86329.C | 11 |
4 files changed, 33 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3e1fa62769f2..68904dfcaadf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,14 @@ 2019-02-14 David Malcolm <dmalcolm@redhat.com> + Backport of r262199 from trunk. + 2018-06-27 David Malcolm <dmalcolm@redhat.com> + + PR c++/86329 + * name-lookup.c (consider_binding_level): Filter out names that + match anon_aggrname_p. + +2019-02-14 David Malcolm <dmalcolm@redhat.com> + Backport of r259720 from trunk. 2018-04-27 David Malcolm <dmalcolm@redhat.com> diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 86fa03b77906..4e8263b2f6ed 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -5873,6 +5873,11 @@ consider_binding_level (tree name, best_match <tree, const char *> &bm, if (!suggestion) continue; + /* Don't suggest names that are for anonymous aggregate types, as + they are an implementation detail generated by the compiler. */ + if (anon_aggrname_p (suggestion)) + continue; + const char *suggestion_str = IDENTIFIER_POINTER (suggestion); /* Ignore internal names with spaces in them. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b52293e45fca..84e11ce4b173 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,13 @@ 2019-02-14 David Malcolm <dmalcolm@redhat.com> + Backport of r262199 from trunk. + 2018-06-27 David Malcolm <dmalcolm@redhat.com> + + PR c++/86329 + * g++.dg/lookup/pr86329.C: New test. + +2019-02-14 David Malcolm <dmalcolm@redhat.com> + Backport of r259720 from trunk. 2018-04-27 David Malcolm <dmalcolm@redhat.com> diff --git a/gcc/testsuite/g++.dg/lookup/pr86329.C b/gcc/testsuite/g++.dg/lookup/pr86329.C new file mode 100644 index 000000000000..fc091ba35de6 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/pr86329.C @@ -0,0 +1,11 @@ +/* PR c++/86329: ensure we don't erroneously offer suggestions like "._0", + which are an implementation detail of how e.g. anonymous enums are + handled internally. */ + +enum {NONEMPTY}; + +int test() +{ + return __0; // { dg-error "'__0' was not declared in this scope" } + // { dg-bogus "suggested alternative" "" { target *-*-* } .-1 } +} |