cancel
Showing results for 
Search instead for 
Did you mean: 

IDE recognition of _Static_assert

Brian H
Senior

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:

BrianH_1-1694553298522.png

Image showing correct compiler treatment of _Static_assert:

BrianH_0-1694553238771.png

To be clear, this is not a show-stopping problem; it's just an annoyance factor.

12 REPLIES 12
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

@TDK _Static_assert is a keyword in C11. (in same line as _Bool etc.)

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.

 

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

Really... why the OP won't just include <assert.h> and use static_assert ...

Eclipse parser should ignore unknown stuff in system includes.

CTapp.1
Associate III

The behaviour is the same for static_assert() and _Static_assert(), but it only happens when they are used at file-scope.

image.png

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

Pavel A.
Evangelist III

Which C language standard is selected in your project settings?

(C/C++ build -> Settings -> MCU GCC Compiler-> General )

Try c17 or gnu17.

 

Thanks, but that gives exactly the same results as C11 (as expected, really).

This looks more like an issue with the Eclipse CDT parser.

Pavel A.
Evangelist III

@mattias norlander  #bugreport  Should this already work in the upstream CDT?

Radosław
Senior II

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