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