Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7953 Discussions

ICC ignores type on class variable definition

Bert_Jonson
Beginner
640 Views

[cpp]class A {
public:
static int t;
};

char A::t;[/cpp]

ICC 13 update 1 on windows compiles this code, but mustn't.

BTW:

Why forum is too slow working?

Sometimes it gives:

Gateway Timeout

The proxy server did not receive a timely response from the upstream server.

0 Kudos
6 Replies
JenniferJ
Moderator
640 Views

Yeh, I can see the issue. thanks for letting us know.

VC2010 and VC2012 will issue an error. icl issued a warning instead. I'll submit to the compiler to look at.

icl warning:
u361639.cpp(7): warning #147: declaration is incompatible with "int A::t" (declared at line  char A::t;

Not sure why the forum server is slow. If it still slow tomorrow, please let me know too.
Thanks!
Jennifer

0 Kudos
SergeyKostrov
Valued Contributor II
640 Views
A static member of a class, even if it is declared with a wrong type 'char', must be initialized with some default value, like: ... class A { public: static int t; }; char A::t = 0; ... So, it looks like there are actually two errors and I'll check what another C/C++ compilers will report. I raise a red-alert and errors like these once are simply not acceptible because the test-case is a classic one.
0 Kudos
SergeyKostrov
Valued Contributor II
640 Views
I'd like to provide results of additional verification. Older version ( 12 ) of Intel C++ compiler also compiles the test-case and at least three test-cases could be considered: [ Test-case 1 ] class A { public: static int t; }; char A::t; Intel C++ compiler: Warning #147: declaration is incompatible with "int A::t" (declared at line 4344) char A::t; ^ Microsoft C++ compiler: Error C2371: 't' : redefinition; different basic types Borland C++ compiler: Error E2356 ... Type mismatch in redeclaration of 'A::t' Error E2344 ... Earlier declaration of 'A::t' MinGW C++ compiler: Error: conflicting declaration 'char A::t' Error: 'A::t' has a previous declaration as `int A::t' Turbo C++ compiler: Error ... Type mismatch in redeclaration of 'A::t' [ Test-case 2 ] class A { public: static int t; }; int A::t; [ Test-case 3 ] class A { public: static int t; }; int A::t = 0;
0 Kudos
SergeyKostrov
Valued Contributor II
640 Views
>>...Why forum is too slow working? Please report any IDZ web-site related issues and problems at: http://software.intel.com/en-us/forums/watercooler-catchall and that forum is monitored by IDZ management.
0 Kudos
Georg_Z_Intel
Employee
640 Views
Hello, I've forwarded your feedback regarding the slow IDZ internally. We cannot promise to improve this in a sudden but at least the correct people are aware of it now. Best regards, Georg Zitzlsberger
0 Kudos
JenniferJ
Moderator
640 Views

This issue is fixed in 14.0 and later. Now ICL also emits the error:

test.cpp(6): error: declaration is incompatible with "int A::t" (declared at line 4)
  char A::t;
          ^

Jennifer

0 Kudos
Reply