False positives for c:M23_053?

Hi, my team is reporting what they believe are false positives for rule C:M23_053 (“The source code used to implement an entity shall appear only once”).
The rule description states that it is part of MISRA C++:2023. I also noted that this same rule is implemented for both C, C++ and Objective-C and they all refer to the same MISRA C++ reference.

However, the C language has its own MISRA rules. One rule in particular from the C guidelines — “An external object or function shall be declared once in one and only one file” — appears to contradict the C++ rule when weak symbols are involved.

Specifically, the C rule states that it:

Ignores compiler‑specific, non‑portable ways of overriding function declarations, such as #pragma weak or __attribute__((weak)).

To me, this MISRA C++ rule should probably be removed and replaced with the corresponding MISRA C rule. What are your thoughts?

Some relevant references:

https://se.mathworks.com/help/bugfinder/ref/misracpp2023rule6.2.3.html

https://se.mathworks.com/help/bugfinder/ref/misrac2023rule8.5.html

Hi @Alix,

Currently, for MISRA compliance purposes, we only support MISRA C++, not MISRA C (but stay tuned…). In that context, when we think a MISRA C++ rule makes some sense for C (or objective C) code, we enable it too.

That being said, for this specific rule, I’m not sure what case would raise for MISRA C++ 6.2.3 but not for MISRA C 8.5. They look very similar… Can you provide an example?

By the way, the documents you reference are not the official MISRA definition for these rules, and the official definitions do not mention #pragma weak or anything similar. Furthermore, the answer in the MISRA C++ forum confirms that flagging function with such an attribute is the right behavior for the rule, even if this attribute gives you good reasons for deviating from it.

Hope that helps!