[Bug c++/52807] New: static constant member variable undefined

sidney.cadot at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Mar 31 12:37:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52807

             Bug #: 52807
           Summary: static constant member variable undefined
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sidney.cadot@gmail.com


The following program compiles but does not link on Linux, g++ 4.6.1, when
compiled with -O0.

$ g++ -O0 showbug.cc -o showbug
/tmp/ccUq3Hog.o: In function `main':
showbug.cc:(.text+0x16): undefined reference to `Foo::FooConstant'
collect2: ld returned 1 exit status

Compiling with any higher optimization level makes the link error disappear.


/////////////////////////// start

#include <iostream>

bool b()
{
    return true;
}

struct Foo
{
    static const int FooConstant = 123;
};

int main()
{
    std::cout << (b() ? Foo::FooConstant : Foo::FooConstant) << std::endl;
    return 0;
}

/////////////////////////// end



More information about the Gcc-bugs mailing list