typename keyword in a declaration requires a qualified type name after it (a type name with a nested name spacifier in front of it). But what is a qualified name of a local class or struct? Here is the example:
struct A{};
namespace bb { struct B{}; }
int main()
{
struct C{};
typename A a; // not OK, because A is not a qualified typename
typename ::A a; // OK, because it contains a nested name specifier
typename B b; // not OK, because B is not a qualified typename
typename bb::B b; // OK, because it contains a nested name specifier
typename C c; // not OK in gcc and clang but compiles in Visual Studio
}
This is the error I get from clang: expected a qualified name after 'typename'
This is the error reported by gcc: <source>:21:14: error: expected nested-name-specifier before 'C'
Is it possible to use a local class name after typename? If so then what is the qualified name of it? The class is reported as main()::C in clang error messages, but that obviously is not its qualified name. I couldn't find a place in the C++ standard that forbids using local classes in this context. Am I missing something? Visual Studio is not complaining about typename C c; so is it a bug in gcc and clang?
PS. I know I can declare variables without typename in front of them if I don't use templates, but I am just curious if this is a bug in the language, a bug in gcc/clang or Visual Studio, or I am missing something.