This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] C++: don't offer bogus "._0" suggestions (PR c++/86329)
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Wed, 27 Jun 2018 15:01:22 -0400
- Subject: [PATCH] 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.
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu;
adds 9 PASS results to g++.sum
OK for trunk, gcc-8, gcc-7 branches?
gcc/cp/ChangeLog:
PR c++/86329
* name-lookup.c (consider_binding_level): Filter out names that
match anon_aggrname_p.
gcc/testsuite/ChangeLog:
PR c++/86329
* g++.dg/lookup/pr86329.C: New test.
---
gcc/cp/name-lookup.c | 5 +++++
gcc/testsuite/g++.dg/lookup/pr86329.C | 11 +++++++++++
2 files changed, 16 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/lookup/pr86329.C
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index a30c374..6ec4e6e 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -5786,6 +5786,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/g++.dg/lookup/pr86329.C b/gcc/testsuite/g++.dg/lookup/pr86329.C
new file mode 100644
index 0000000..fc091ba
--- /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 }
+}
--
1.8.5.3