Description
The TinyCBOR wrapper currently applies the following workaround:
if(CMAKE_C_COMPILER_ID STREQUAL "GNU"
AND CMAKE_C_COMPILER_VERSION VERSION_LESS 10)
target_compile_options(tinycbor PRIVATE
"-D__has_cpp_attribute(x)=0")
endif()
However, the corresponding upstream TinyCBOR issue affects GCC versions
earlier than GCC 11, including GCC 10:
#293
#294
With GCC < 11 in C99 mode, __has_cpp_attribute(fallthrough) evaluates
as supported, but the C compiler cannot parse the resulting
[[fallthrough]] attribute.
The compilation error is similar to:
compilersupport_p.h:57:41: error: expected expression before '[' token
#define CBOR_FALLTHROUGH [[fallthrough]]
This was reproduced locally with Arm GNU Toolchain 9.3.1 using -std=c99.
Problem
The condition VERSION_LESS 10 excludes GCC 10 even though GCC 10 is
also affected.
Defining __has_cpp_attribute from the command line is also only a
workaround and can produce a macro redefinition warning.
Expected behavior
TinyCBOR should compile in C99 mode with GCC 9 and GCC 10 without
overriding compiler feature-test macros.
Suggested solution
Preferred solution:
Update the bundled TinyCBOR source to v7.0 or later; or
Backport upstream commit:
45e4641
The upstream fix distinguishes C and C++ attribute detection:
#if defined(__has_cpp_attribute) && defined(__cplusplus)
/* C++ attribute detection */
#elif defined(__has_c_attribute) && !defined(__cplusplus)
/* C23 attribute detection */
#endif
Description
The TinyCBOR wrapper currently applies the following workaround:
However, the corresponding upstream TinyCBOR issue affects GCC versions
earlier than GCC 11, including GCC 10:
#293
#294
With GCC < 11 in C99 mode, __has_cpp_attribute(fallthrough) evaluates
as supported, but the C compiler cannot parse the resulting
[[fallthrough]] attribute.
The compilation error is similar to:
This was reproduced locally with Arm GNU Toolchain 9.3.1 using -std=c99.
Problem
The condition VERSION_LESS 10 excludes GCC 10 even though GCC 10 is
also affected.
Defining __has_cpp_attribute from the command line is also only a
workaround and can produce a macro redefinition warning.
Expected behavior
TinyCBOR should compile in C99 mode with GCC 9 and GCC 10 without
overriding compiler feature-test macros.
Suggested solution
Preferred solution:
Update the bundled TinyCBOR source to v7.0 or later; or
Backport upstream commit:
45e4641
The upstream fix distinguishes C and C++ attribute detection: