Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
61 Views

icc compiles incorrect code

[cpp]

int main() {
switch(0) {
default:
}
}

[/cpp]

This code must not compiles(as it is on gcc/msvc) because it's need ";" before "}".

ICC 13 update 1 on win.

0 Kudos
5 Replies
Highlighted
Valued Contributor II
61 Views

Thanks, Bert. However, Intel C++ compiler actually displays a warning #127 ( expected a statement ). >>switch(0) { >>default: >>} I've done a quick verification and here are compilation outputs for different C++ compilers: [ Intel C++ compiler ] ... .\../../Common/PrtTests.cpp(8745): warning #127: expected a statement } ^ [ Microsoft C++ compiler ] ... ..\prttests.cpp(8745) : error C2143: syntax error : missing ';' before '}' ..\prttests.cpp(8745) : warning C4065: switch statement contains 'default' but no 'case' labels [ MinGW C++ compiler ] ... ../../Common/PrtTests.cpp:8745: error: expected primary-expression before '}' token ../../Common/PrtTests.cpp:8745: error: expected `;' before '}' token [ Borland C++ compiler ] ... Error E2379 ../../Common/PrtTests.cpp 8745: Statement missing ; in function RunTest1017() [ Turbo C++ compiler ] ... Error ../../Common/PrtTests.cpp 8745: Statement missing ; in function RunTest1017()
0 Kudos
Highlighted
Beginner
61 Views

Sorry, because of some troubles i have all warnings disabled on icc.

But anyway it should be en error.

0 Kudos
Highlighted
Employee
61 Views

Hello, I agree to Sergey that the warning usually should be enough here. If someone really wants this to be an error, the option /WX (warnings to errors) can be used. Nevertheless, Microsoft Visual Studio* compiler treats it as an error and maybe we should too, for compatibility reasons. Hence, I've asked engineering to raise severity of this warning to an error. Edit: Created ticket for this feature request: DPD200240577 It also is only a warning on Linux* but an error with GNU GCC*. Best regards, Georg Zitzlsberger
0 Kudos
Highlighted
Valued Contributor II
61 Views

>>...But anyway it should be en error. Yes and here is additional verification with a 23-year-old Turbo C++ compiler: [ Turbo C++ Version 1.01 ] ... Turbo C++ Version 1.01 Copyright (c) 1990 Borland International test.c: Error test.c 6: Statement missing ; in function main *** 1 errors in Compile *** ... [ Test-case ] void main( void ) { switch( 0 ) { default: } } PS: That is a really good catch!
0 Kudos
Highlighted
Employee
61 Views

Hello,

just FYI: DPD200240577 has been rejected.

ICC is more tolerant by default here and there is a way to turn warnings into errors (/WX) in case you still want strict checking.

Best regards,

Georg Zitzlsberger

0 Kudos