This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/37175] New: Undefined reference to static const member in var = condition ? X::A : X::B
- From: "wjaczews at o2 dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Aug 2008 09:42:48 -0000
- Subject: [Bug c++/37175] New: Undefined reference to static const member in var = condition ? X::A : X::B
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Cannot compile with -O0 or -O1, or without specifing optimization.
1.c:
#include <iostream>
struct X {
static const int ABC = 1;
static const int DEF = 2;
};
int main(int argc, char * argv[])
{
std::cout << (argc > 1 ? X::ABC : X::DEF) << std::endl;
}
> g++ 1.cpp
/tmp/cc49NOpp.o: In function `main':
1.cpp:(.text+0x18d): undefined reference to `X::ABC'
1.cpp:(.text+0x197): undefined reference to `X::DEF'
collect2: ld returned 1 exit status
The same result on gcc-4.2, 4.3, 4.4
> g++ -v
Reading specs from /usr/lib/gcc/i486-slackware-linux/4.2.3/specs
Target: i486-slackware-linux
Configured with: ../gcc-4.2.3/configure --prefix=/usr --enable-shared
--enable-languages=ada,c,c++,fortran,java,objc --enable-threads=posix
--enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose
--with-arch=i486 --target=i486-slackware-linux --host=i486-slackware-linux
Thread model: posix
gcc version 4.2.3
> g++-4.3 -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.3.1/configure --prefix=/usr/local/gcc-4.3.1
Thread model: posix
gcc version 4.3.1 (GCC)
> g++-4.4 -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.4-20080808/configure
--prefix=/usr/local/gcc-4.4-20080808
Thread model: posix
gcc version 4.4.0 20080808 (experimental) (GCC)
--
Summary: Undefined reference to static const member in var =
condition ? X::A : X::B
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: wjaczews at o2 dot pl
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37175