Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
7783 Discussions

fallthrough attribute unsupported, contrary to icc's claims

nemequ
New Contributor I
1,080 Views

GCC has supported __attribute__((__fallthrough__)) since version 7. ICC claims __GNUC__ >= 7, though it does not support the fallthrough attribute.

 

Perhaps more problematically (I'm used to compilers lying about __GNUC__), as of version 2021.2.0, ICC now advertises support for the fallthrough attribute via __has_attribute(fallthrough). Earlier versions (even those which define the __has_attribute macro) do not make this claim.

int foo(int bar) {
    int r = 0;

    switch (bar) {
        case 0:
            r += 1;
            #if defined(__has_attribute) && __has_attribute(fallthrough)
            __attribute__((__fallthrough__)); 
            #endif
        case 1:
            r += 2;
            break;
    }

    return r;
}

Results in "warning #2621: attribute "__fallthrough__" does not apply here".

 

Here is a link to the example on godbolt: https://godbolt.org/z/senjfaoao

Labels (1)
0 Kudos
3 Replies
RahulV_intel
Moderator
1,059 Views

Hi,

 

Thanks for reporting this issue. ICC throws a warning with the 2021.2 version. We are working on this internally and will get back to you with an update.

 

Thanks,

Rahul

 

nemequ
New Contributor I
1,039 Views

Probably related: I just noticed that __has_cpp_attribute(clang::fallthrough) also returns true, but [[clang::fallthrough]] generates "warning #3924: attribute namespace "clang" is unrecognized".

 

Test on Compiler Explorer: https://godbolt.org/z/ExadrM8ve

 

Similarly, __has_cpp_attribute(fallthrough) returns true, but [[fallthrough]] generates a "warning #1292: unknown attribute "fallthrough"": https://godbolt.org/z/6j3jGK4qn

Viet_H_Intel
Moderator
917 Views

This issue has been fixed in oneAPI 2021.3. We will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.

Thanks,



Reply