This seems to compile correctly:
namespace A {
template<typename T>
struct S {};
namespace B {
using S = S<int>;
}
}
int main() {
using namespace A::B;
S s;
}
Even though at the line using S = S<int>
, the first S
refers to A::B::S
, whereas the second S
refers to the template A::S
.
Is this standard C++?
The scope of S
begins at its point of declaration, and for a using
declaration it is after the type-id to which the alias refers (S<int>
).
So inside of the declaration, the scope of the new S
has not started yet, and S
still refers to A::S
.
According to https://en.cppreference.com/w/cpp/language/scope#Point_of_declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With