class A {
};
class B {
using C = A;
// Compilation error:
// Type alias 'C' cannot be referenced with a class specifier
friend class C;
};
Why is a type alias not allowed to be a friend class name in C++?
What's the rationale behind?
You're wrong in assuming that a type alias is not allowed to be in a friend declaration. The correct syntax for befriending through alias
Cisfriend C;instead offriend class C;.Note also that the program is ill-formed and msvc is wrong in not giving a diagnostic. This can be seen from dcl.type.elab:
(emphasis mine)
And since the identifier
Cdoes resolve to a typedef-name the elaborated-type-specifier(class C) and hence the program is ill-formed.