MISRA Discussion Forums
Does rule A2-10-5 apply to reusing an external identifier as a member identifier? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: AUTOSAR C++:2014 rules (https://forum.misra.org.uk/forumdisplay.php?fid=185)
+--- Thread: Does rule A2-10-5 apply to reusing an external identifier as a member identifier? (/showthread.php?tid=1777)



Does rule A2-10-5 apply to reusing an external identifier as a member identifier? - mstaron - 06-07-2026

Rule A2-10-5 states: Regardless of scope, no identifier with static storage duration should be reused across any source files in the project. Are cases where an identifier is reused as a member non-compliant with this rule? In particular, the case where an operator function is defined as a global and a member function.
Code:
struct S
{
  void operator<<(S&) {}
  void f1(int par) {}
};

namespace N
{
  void operator<<(int i, S&) {}  // Is compliant or non-compliant?
  void f1(int par) {}            // Is compliant or non-compliant?
}



RE: Does rule A2-10-5 apply to reusing an external identifier as a member identifier? - misra cpp - 10-07-2026

We agree that the wording of this rule is unclear.

However, your forum post example doesn't contain any function declared 'static', so the rule does not apply.

More generally, it was felt this rule was too restrictive and so was not included in the ruleset for MISRA C++:2023


RE: Does rule A2-10-5 apply to reusing an external identifier as a member identifier? - mstaron - 15-07-2026

Rule A2-10-5 mentions 'function with static storage duration'. Was this meant to apply only to functions declared with the 'static' keyword? The rule documentation states "Regardless of scope, no identifier with static storage duration should be re-used across any source files in the project. This includes objects or functions with external linkage and any objects or functions with the static storage class specifier." Can we assume this was inserted incorrectly and the rule is meant to apply only to functions with 'static' (that do not have external linkage)?


RE: Does rule A2-10-5 apply to reusing an external identifier as a member identifier? - misra cpp - 17-07-2026

The basic problem with A2-10-5 is that it implies that functions can have static storage duration, this is incorrect.

We think what was intended was that the name of functions with internal linkage should not be reused anywhere in the program, this includes both functions declared with the static keyword and those declared in an anonymous namespace (as of C++ 2011).
All the functions in your example have external linkage, so the rule does not apply, so your code is compliant.

As far as object declarations are concerned, the Autosar rule text is unambiguous and the rule applies to non-member objects with internal or external linkage.