https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81073

            Bug ID: 81073
           Summary: link failure as C++ misses to instanciate some objects
           Product: gcc
           Version: 7.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gjl at gcc dot gnu.org
  Target Milestone: ---

$ g++ struct.cpp -Os -save-temps

the following C++ test case struct.cpp:


struct test { const int *addr; };

const test* setup()
{
    static constexpr test atest =
    {
        ({ static const int inner = 123; &inner; })
    };

    return &atest;
}

int main(){}


This gives a linker error:

struct.o:(.rodata+0x0): undefined reference to `setup()::inner'

"atest" is initialized as expected with a reference to _ZZ5setupvE5inner, but
that object is never instanciated, resulting in a link failure.

Seeing this with v7.1 on and for x86_64-linux-gnu, also on trunk (future v8).

Reply via email to