[Bug c++/26597] New: static const class member, ?:, undefined reference
teufl at weyl dot math dot tugraz dot at
gcc-bugzilla@gcc.gnu.org
Tue Mar 7 19:18:00 GMT 2006
Consider the following code:
=== bug.cpp ===
struct Test {
static const int number=5;
int test(const int n);
};
int Test::test(const int n)
{
int max = number > n ? number : n;
return max;
}
int main()
{
Test t;
t.test(6);
return 0;
}
============
I get the following linker error:
/tmp/ccWCtyqx.o(.text+0x18): In function `Test::test(int)':
: undefined reference to `Test::number'
collect2: ld returned 1 exit status
I have tested g++ 3.3.5, 4.0.2, and 4.1.0. With g++ 4.* and -O2 the error
disappears. Also if one replaces the ? : by an if statement, the error
disappears. Of course, an additional "extern const int Test::number;" also
solves the problem.
Environment: i386-linux (Debian GNU/Linux)
Releases: 3.3.5, 4.0.2, 4.1.0
How-To-Repeat: g++ -o bug bug.cpp
Best regards,
Elmar
--
Summary: static const class member, ?:, undefined reference
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: teufl at weyl dot math dot tugraz dot at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26597
More information about the Gcc-bugs
mailing list