[cfe-dev] Clang and C++Ox : what I'm doing wrong

John McCall rjmccall at apple.com
Fri Oct 8 08:49:15 PDT 2010


On Oct 8, 2010, at 8:47 AM, Argyrios Kyrtzidis wrote:

> On Oct 8, 2010, at 12:27 AM, 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;
>> };
>> 
>> 
>> int main()
>> {
>>  cout << "hello "  << Test::value << endl;
>>  return 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]
>>    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
> 
> Why are we requiring a definition for Test::value, isn't this supposed to be used as a constant ? John ?

Probably various places don't realize that they can emit that as a constant.

John.





More information about the cfe-dev mailing list