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)
commit5da1234bb7aaf95dd7e3b5e5438cd92be95daf0f
tree12eafa9bd3a739d78c5cd45154533aa9946be2cd
parentb4324a144b4499725143baf1f69722f92814572e
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:
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]