![]() |
|
Rule 6.9.1 and (possibly) qualified identifiers / name lookup / namespaces - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=188) +---- Forum: 4.6 Basic concepts (https://forum.misra.org.uk/forumdisplay.php?fid=192) +---- Thread: Rule 6.9.1 and (possibly) qualified identifiers / name lookup / namespaces (/showthread.php?tid=1766) |
Rule 6.9.1 and (possibly) qualified identifiers / name lookup / namespaces - ckaiser - 24-04-2026 Hello, We are wondering how Rule 6.9.1 shall be understood when namespaces and name lookups are involved. Rule's rationale is about avoiding confusion. But, especially, the examples only address very basic (mis)uses, i.e., using obviously different type (alias) names in (re-)declarations. Very C-like... It is unclear, when it comes to (namespace) qualification and (re-)introducing names into namespaces or scopes. Under those conditions, it becomes fuzzy what is meant with "the same type alias": Is it just the spelling of the name (including qualification)? Is it the definition, i.e. resulting the underlying type? Or, is it the same qualified name (regardless how it was spelled in code - i.e., whether and how it was qualified)? Maybe, it even is (or should be) out of scope of rule 6.9.1? Example: Code: namespace n {Note: to keep the examples simple, I'd judge "compliance" always only considering any difference to the initial declaration, e.g., (0). (In practice, one violating declaration probably would cause the whole set of declarations being not compliant.) (1): Is most definitely compliant, as both indeed use the very same type alias, in all respects. (2): Compliant? It "names" the same alias, but it is "spelled" (i.e., it looks) differently. Might lead to confusion? (3): Compliant? Maybe; which alias will be used? Should it matter in this case? (4): Compliant? Same (unqualified) name ist used, but in the end it is a different alias, still resulting in the same type. Regarding the underlying type, one could argue, it is still the same alias. (5): Compliant? Similar to (4); just to demonstrate a friend declaration. (6): Compliant? Original declaration didn't even use a type alias - maybe, not even in scope? Still same "name". (7): Compliant? IMO, actually not in scope, because type aliases are not used in any declaration of that entity. Personally, I don't have a strong opinion on that. I just found declarations of those kinds in our codebase. Thus, I'm asking for clarification. IMHO, using same names (qualified or unqualified) seems to match expectations it could be okay, as long as they do result in same types. Mixing different qualifications within one scope (class or namespace) is quite confusing as well (such as (1) and (2), even though namespace qualification is required for (2)) Thank you very much, Best regards. RE: Rule 6.9.1 and (possibly) qualified identifiers / name lookup / namespaces - misra cpp - 18-05-2026 Under the current wording of 6.9.1; examples 1 & 2 are compliant, and 3 to 6 are non-compliant. However, the rule's wording is currently under review, considering whether code like 3 & 4 should be allowed. Example 7 is 'rule does not not apply' |