C++: don't offer bogus "._0" suggestions (PR c++/86329)
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 27 Jun 2018 23:21:46 +0000 (23:21 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Wed, 27 Jun 2018 23:21:46 +0000 (23:21 +0000)
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:
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.

From-SVN: r262199

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/pr86329.C [new file with mode: 0644]

index 05383b6003abf4a998959d4f0f4a5954dcc50a46..040a84d021693cf1d6a0457622f36dc265005b79 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2018-06-27  Jason Merrill  <jason@redhat.com>
 
        * name-lookup.c (do_pushtag): If we skip a class level, also skip
index e0500d83071113dd98573e6c64e2bbeb267821ec..3aafb0f0ccf8190fa3416fdb30458c14f2e480a7 100644 (file)
@@ -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.  */
index e9e2e2a77680280c50f114c29f696cf7f182f248..3b33d2051f004075258a9a557ba3d51a179de231 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-27  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c++/86329
+       * g++.dg/lookup/pr86329.C: New test.
+
 2018-06-27  Carl Love  <cel@us.ibm.com>
 
 Add test case that was supposed to be added in commit 255556 on 2017-12-11.
diff --git a/gcc/testsuite/g++.dg/lookup/pr86329.C b/gcc/testsuite/g++.dg/lookup/pr86329.C
new file mode 100644 (file)
index 0000000..fc091ba
--- /dev/null
@@ -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 }
+}