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: unassig...@gcc.gnu.org ReportedBy: sidney.ca...@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