Skip to content

Conversation

@thiagomacieira
Copy link
Member

@thiagomacieira thiagomacieira commented Apr 2, 2025

I think GCC says __has_cpp_attribute(fallthrough) is true because C++ supports it (it means "has C++ attribute"), but that doesn't apply to the C language. This causes a compilation error:

compilersupport_p.h:57:41: error: expected expression before '[' token
   57 | #    define CBOR_FALLTHROUGH            [[fallthrough]]
      |                                         ^
cborparser.c:225:13: note: in expansion of macro 'CBOR_FALLTHROUGH'
  225 |             CBOR_FALLTHROUGH;
      |             ^~~~~~~~~~~~~~~~

Instead, we should use the C23 __has_c_attribute to detect the C attribute.

Fixes #293.

… in C

I think GCC says `__has_cpp_attribute(fallthrough)` is true because C++
supports it (it means "has C++ attribute"), but that doesn't apply to
the C language. This causes a compilation error:

```
compilersupport_p.h:57:41: error: expected expression before '[' token
   57 | #    define CBOR_FALLTHROUGH            [[fallthrough]]
      |                                         ^
cborparser.c:225:13: note: in expansion of macro 'CBOR_FALLTHROUGH'
  225 |             CBOR_FALLTHROUGH;
      |             ^~~~~~~~~~~~~~~~
```

Instead, we should use the C23 `__has_c_attribute` to detect the C
attribute.

Fixes intel#293.

Signed-off-by: Thiago Macieira <[email protected]>
@thiagomacieira thiagomacieira force-pushed the Fix_build_with_GCC_11_fallthrough_is_supported_but_not_allowed_in_C branch from 41acfa8 to fe675e3 Compare April 2, 2025 23:47
@thiagomacieira thiagomacieira merged commit 45e4641 into intel:main Apr 8, 2025
9 checks passed
@thiagomacieira thiagomacieira deleted the Fix_build_with_GCC_11_fallthrough_is_supported_but_not_allowed_in_C branch April 8, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The code does not compile on ubuntu 20.04/gcc 9.4 after recent change in compilersupport_p.h

1 participant