Skip to main content
Brian H
Senior
September 12, 2023
Question

IDE recognition of _Static_assert

  • September 12, 2023
  • 6 replies
  • 7999 views

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.

    This topic has been closed for replies.

    6 replies

    TDK
    Super User
    September 12, 2023

    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.
    Super User
    September 13, 2023

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

    TDK
    Super User
    September 13, 2023

    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""."
    CTapp.1
    Senior III
    October 2, 2023

    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

    All posts are made in a personal capacityMISRA C++ ChairMISRA C WG MemberDirector The MISRA Consortium Limited (TMCL)
    Pavel A.
    Super User
    October 2, 2023

    Which C language standard is selected in your project settings?

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

    Try c17 or gnu17.

     

    CTapp.1
    Senior III
    October 3, 2023

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

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

    All posts are made in a personal capacityMISRA C++ ChairMISRA C WG MemberDirector The MISRA Consortium Limited (TMCL)
    Pavel A.
    Super User
    October 3, 2023

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

    Radosław
    Associate II
    January 29, 2024

    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

    Associate II
    February 1, 2024

    That worked for me.  Thanks!

    Radosław
    Associate II
    February 3, 2024

    think it's impossible.   I'm usually pass this tips in ReadMe , ;)