$ cat suggest.c enum { TYPE_A, } int fn(void) { int b = TYPE_B; int c = TYPE_C; int d = TYPE_D; return 0; } $ gcc -O3 -Wall -c suggest.c suggest.c: In function 'fn': suggest.c:7:13: error: 'TYPE_B' undeclared (first use in this function); did you mean 'TYPE_A'? int b = TYPE_B; ^~~~~~ TYPE_A suggest.c:7:13: note: each undeclared identifier is reported only once for each function it appears in suggest.c:8:13: error: 'TYPE_C' undeclared (first use in this function); did you mean 'TYPE_B'? int c = TYPE_C; ^~~~~~ TYPE_B suggest.c:9:13: error: 'TYPE_D' undeclared (first use in this function); did you mean 'TYPE_C'? int d = TYPE_D; ^~~~~~ TYPE_C For some reason, for every new undeclared identifier gcc suggest to use a previously reported (but apparently similar) undeclared identifier. Shouldn't it always suggest TYPE_A, the only defined identifier?
Thanks for filing this. Confirmed: this still affects trunk, with the C frontend (the "-O3 -Wall" aren't needed). The C++ frontend doesn't seem to be affected.
Candidate patch: https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01907.html
Author: dmalcolm Date: Tue Nov 21 21:59:53 2017 New Revision: 255038 URL: https://gcc.gnu.org/viewcvs?rev=255038&root=gcc&view=rev Log: C: don't suggest names that came from earlier failures (PR c/83056) PR c/83056 reports an issue affecting trunk and gcc-7 in which the C frontend's implementation of lookup_name_fuzzy uses undeclared identifiers as suggestions when encountering subsequent undeclared identifiers. The fix is to filter out the names bound to error_mark_node in lookup_name_fuzzy. The C++ frontend is unaffected, as it already does this. gcc/c/ChangeLog: PR c/83056 * c-decl.c (lookup_name_fuzzy): Don't suggest names that came from earlier failed lookups. gcc/testsuite/ChangeLog: PR c/83056 * gcc.dg/spellcheck-pr83056.c: New test case. Added: trunk/gcc/testsuite/gcc.dg/spellcheck-pr83056.c Modified: trunk/gcc/c/ChangeLog trunk/gcc/c/c-decl.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk for gcc 8 by r255038; not yet fixed on gcc-7-branch.