The following code compiles with all 3 major compilers without any problems (MSVC has a bug with accepting of invalid similar code, but that is unrelated to my question):
#include <iostream>
namespace Z{
struct Na{
struct Batman{
int x=47;
};
};
}
int main(){
using Na = Z::Na;
return Na::Na::Na::Na::Na::Na::Na::Batman{}.x;
}
Is there any logic behind this, or is it just a weird edge case that ends up being legal when applying rules made for "normal" uses?
If my confusion is not clear: I would expect the weird line to be parsed either as
- many nested namespaces, e.g.
std::std::std
and rejected - a reference to a constructor (
Na::Na
) and then rejected when the following::Na
is encountered