This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52807] New: static constant member variable undefined
- From: "sidney.cadot at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 31 Mar 2012 12:34:46 +0000
- Subject: [Bug c++/52807] New: static constant member variable undefined
- Auto-submitted: auto-generated
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