intel / intel/tinycbor

GCC 10 is not covered by the TinyCBOR fallthrough compatibility workaround

Open
#334 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
630
Forks
222
Avg merge
1d 3h
Merged PRs (30d)
1

Description

## Description

The TinyCBOR wrapper currently applies the following workaround:

```cmake
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:

https://github.com/intel/tinycbor/issues/293
https://github.com/intel/tinycbor/pull/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:
```c
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:
https://github.com/intel/tinycbor/commit/45e4641059709862b4e46f3608d140337566334b
The upstream fix distinguishes C and C++ attribute detection:
```c
#if defined(__has_cpp_attribute) && defined(__cplusplus)
/* C++ attribute detection */
#elif defined(__has_c_attribute) && !defined(__cplusplus)
/* C23 attribute detection */
#endif
```

Contributor guide

Open the contributing guide

Research direction

Inspect the wrapper's CMake workaround and the bundled TinyCBOR compilersupport_p.h, then compare them with upstream TinyCBOR v7.0 or commit 45e4641059709862b4e46f3608d140337566334b. Build the library in C99 mode with GCC 9 and GCC 10; done means both compile without overriding compiler feature-test macros or producing the fallthrough attribute error.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cmake
Domain
build-system, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.