[Bug c++/20547] New: undefined reference to "static const" fields of classes
Hu dot YuehWei at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Mar 19 06:59:00 GMT 2005
The sample codes¡G
==========================================
#include <iostream>
#include <vector>
struct T
{
static char const a = 3;
};
std::vector<char> ddd;
int
main()
{
ddd.push_back(T::a); /* this line of codes trigger the errors */
std::cerr << ddd.front() << std::endl;
return 0;
}
========================================
gcc-3.0.x 3.2.x 3.3.x 3.4.x compile the above program will produce errors like this:
=======================================
/tmp/ccPOPHZ6.o(.text+0x124): In function `main':
: undefined reference to `T::a'
collect2: ld returned 1 exit status
=======================================
However, if I use gcc-2.95, then there will be no errors.
If I modify the codes from:
...
ddd.push_back(T::a);
...
to
...
ddd.push_back(static_cast<char>(T::a));
...
then gcc-3.0.x 3.2.x 3.3.x 3.4.x will be fine.
Is this a bug in gcc 3.x?
--
Summary: undefined reference to "static const" fields of classes
Product: gcc
Version: 3.4.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Hu dot YuehWei at gmail dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20547
More information about the Gcc-bugs
mailing list