Community
cancel
Showing results for 
Search instead for 
Did you mean: 
nemequ
New Contributor I
116 Views

fallthrough attribute unsupported, contrary to icc's claims

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
2 Replies
RahulV_intel
Moderator
95 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
75 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

Reply