icc compiles incorrect code

icc compiles incorrect code

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

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 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

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

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

But anyway it should be en error.

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

>>...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!

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui