Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 6.9.1 and (possibly) qualified identifiers / name lookup / namespaces
#1
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 {
struct S {};
using Alias = S;
Alias foo(); // (0)
S bar();
}

auto n::foo() -> Alias; // (1)
n::Alias n::foo(); // (2) with leading return type I have to use the namespace.

using Alias = n::Alias;
auto n::foo() -> Alias; // (3)
Alias n::foo(); // (4)

namespace m {
class Klass {
public:
    using S = n::S;
    using Alias = n::S;
    friend Alias n::foo(); // (5)
    friend S n::bar(); // (6)
    explicit Klass(n::S const&);
};

using n::S;
auto Klass(S const&); // (7)
}
First observation: It doesn't seem to be always about type aliases, but about the question, wich type (name) will be eventually used. This might be out of scope of Rule 6.9.1, but it is still related to developer's expectation / possible confusion.

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.
Reply


Messages In This Thread
Rule 6.9.1 and (possibly) qualified identifiers / name lookup / namespaces - by ckaiser - 24-04-2026, 02:10 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)