Skip to main content
Brian H
Senior
Sep 12, 2023 9:16 PM UTC
Question

IDE recognition of _Static_assert

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.

    12 replies

    TDK
    Sep 12, 2023 9:24 PM UTC

    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.
    Sep 13, 2023 8:13 AM UTC

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

    TDK
    Sep 13, 2023 1:16 PM UTC

    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
    Oct 2, 2023 1:53 PM UTC

    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 capacity. MISRA C++ Chair, MISRA C WG Member, Director The MISRA Consortium Limited (TMCL)
    Pavel A.
    Oct 2, 2023 9:44 PM UTC

    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
    Oct 3, 2023 1:28 PM UTC

    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 capacity. MISRA C++ Chair, MISRA C WG Member, Director The MISRA Consortium Limited (TMCL)
    Pavel A.
    Oct 3, 2023 1:30 PM UTC

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

    Radosław
    Associate II
    Jan 29, 2024 8:13 AM UTC

    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
    Feb 1, 2024 8:58 PM UTC

    That worked for me.  Thanks!

    Radosław
    Associate II
    Feb 3, 2024 8:33 PM UTC

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