This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/88320] GCC suggests variables that don't exist yet
- From: "dmalcolm at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 04 Dec 2018 22:09:32 +0000
- Subject: [Bug c++/88320] GCC suggests variables that don't exist yet
- Auto-submitted: auto-generated
- References: <bug-88320-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88320
--- Comment #6 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
I did a little investigation of this.
A tweaked reproducer, for both C and C++:
int test (void)
{
int vresults1 = 0;
int aresult = aresults +1;
return aresult;
}
I think that we should omit any decls that are being initialized when
considering possible suggestions to offer; hence we would suggest "vresults1"
as the closest match for "aresults" within the initializer.
I believe this is fairly easy to implement for the C frontend: the C FE has a
global "constructor_decl" and a chain of further "in-flight" decls in
"initializer_stack", set up in start_init, and cleared by finish_init:
(gdb) p constructor_decl
$4 = <var_decl 0x7ffff7ffbb40 aresult>
So we should exclude those decls from suggestions.
Something similar is probably doable to the C++ FE, but there doesn't seem to
be an equivalent handy record of which decls are being initialized within the
parser. There is a start_decl and a cp_finish_decl, but they don't seem to be
exact opposites.
I'll continue to poke at this.