2023-09-12 02:16 PM
The STM32 compiler toolchain supplied with CubeIDE 1.13.1 recognizes the _Static_assert statement, but the IDE itself does not (it marks it as a syntax error). Can this be fixed? Is there a setting I can change in the IDE to stop flagging _Static_assert as a syntax error without turning off all syntax checking?
Image showing IDE highlighting _Static_assert statement as a syntax error:
Image showing correct compiler treatment of _Static_assert:
To be clear, this is not a show-stopping problem; it's just an annoyance factor.
2023-09-12 02:24 PM
Where is _Static_assert defined? The IDE needs to know about it and see the appropriate headers before the statement. Sometimes rebuilding the index can be required. Project -> C/C++ Index -> Rebuild. If you hit F3 on it, does it jump to the right definition?
You can use static_assert instead, which the IDE will recognize.
2023-09-13 01:13 AM
@TDK _Static_assert is a keyword in C11. (in same line as _Bool etc.)
2023-09-13 06:16 AM
Had no idea. I use C++ most of the time and there it's static_assert.
I see that in C23 _Static_assert is deprecated in favor of static_assert.
FWIW, my STM32CubeIDE recognizes _Static_assert as a keyword.
2023-09-13 06:41 AM - edited 2023-09-13 06:44 AM
Really... why the OP won't just include <assert.h> and use static_assert ...
Eclipse parser should ignore unknown stuff in system includes.
2023-10-02 06:53 AM - edited 2023-10-02 06:54 AM
The behaviour is the same for static_assert() and _Static_assert(), but it only happens when they are used at file-scope.
It looks as if the parser does not like function call syntax at file-scope - but they all compile as expected.
I would like to use them at file scope to check things like alignment and sizes, but I am going to have to move them into a "random" function if I want to get rid of the error markers.
Edited to fix typo
2023-10-02 02:44 PM - edited 2023-10-02 02:45 PM
Which C language standard is selected in your project settings?
(C/C++ build -> Settings -> MCU GCC Compiler-> General )
Try c17 or gnu17.
2023-10-03 06:28 AM
Thanks, but that gives exactly the same results as C11 (as expected, really).
This looks more like an issue with the Eclipse CDT parser.
2023-10-03 06:30 AM - edited 2023-10-03 06:32 AM
@mattias norlander #bugreport Should this already work in the upstream CDT?
2024-01-29 12:13 AM
In Project --> Properties --> C/C++ General --> Preprocessor Include Paths, Macros etc. add (as a USER ENTRY) an empty macro definition like
_Static_assert(a,b)
On the Entries tab, select CDT User Setting Entries
then click Add...
and pick Preprocessor Macro in the drop-down