icc compiles incorrect code

icc compiles incorrect code

int main() {
 switch(0) {

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

ICC 13 update 1 on win.

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Thanks, Bert. However, Intel C++ compiler actually displays a warning #127 ( expected a statement ).

>>switch(0) {

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()

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

But anyway it should be en error.


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.

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

>>...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
Error test.c 6: Statement missing ; in function main
*** 1 errors in Compile ***

[ Test-case ]

void main( void )
switch( 0 )

PS: That is a really good catch!

Leave a Comment

Please sign in to add a comment. Not a member? Join today