This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/88320] GCC suggests variables that don't exist yet


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]