[cfe-dev] Clang and C++Ox : what I'm doing wrong
Sebastian Redl
sebastian.redl at getdesigned.at
Fri Oct 8 01:10:32 PDT 2010
On 08.10.2010, at 09:27, Jaonary Rabarisoa wrote:
> Hi all,
>
> I trying build the following simple code that use a static const variable inside a class but I got an undefinend reference error :
>
> #include <iostream>
>
> using namespace std;
>
> class Test
> {
> public :
> static const double value = 10.0;
> };
> This code produce the following warning and error at link time :
>
> clang: warning: argument unused during compilation: '-cc1'
> /home/jrabarisoa/Sandbox/test_clang/main.cpp:27:25: warning: in-class initializer for static data member of type 'const double' is a
> C++0x extension [-Wc++0x-extensions]
You're not actually compiling as C++0x.
> static const double value = 10.0;
> ^ ~~~~
> 1 warning generated.
> Linking CXX executable test
> g++: unrecognized option '-cc1'
> CMakeFiles/test.dir/main.cpp.o: In function `main':
> /home/jrabarisoa/Sandbox/test_clang/main.cpp:(.text+0x7a): undefined reference to `Test::value'
> collect2: ld returned 1 exit status
>
> What I've missed ?
Since you didn't compile as C++0x, I can't be sure if the same issue exists there, but C++03 requires a definition of static class members unless it's an integral constant whose lvalue is never needed. I don't know if C++0x extends this to all literal type constants. I wouldn't be surprised if Clang requires the definition anyway.
Sebastian
More information about the cfe-dev
mailing list