Consider this code:
using type = long;
namespace n {
using type = long;
}
using namespace n;
int main() {
type t;
}
This compiles cleanly on Clang 3.7 and GCC 5.3, but MSVC 19* gives the following error message:
main.cpp(9): error C2872: 'type': ambiguous symbol
main.cpp(1): note: could be 'long type'
main.cpp(4): note: or 'n::type'
Is this code well-formed? What part of the standard notes whether the alias is resolved before ambiguity checks?
Note that Clang and GCC both give similar errors to MSVC if you change one of those aliases.
I'm fully aware of how qualifying the name would resolve the ambiguity, I'm just interested in what the standard has to say about this.
*- Just paste the code and run it at that link, I don't know if there's an online MSVC compiler with permalinks
[namespace.udir]/6:
If name lookup finds a declaration for a name in two different namespaces, and the declarations do not declare the same entity and do not declare functions, the use of the name is ill-formed.
However, these do declare the name to refer to the same type, hence the program should be well-formed. This interpretation is e.g. confirmed by the comments in core issue 1894:
//[..]
namespace C {
// The typedef does not redefine the name S in this
// scope, so issue 407's resolution does not apply.
typedef A::S S;
using A::S;
// **The name lookup here isn't ambiguous, because it only finds one
// entity**, but it finds both a typedef-name and a non-typedef-name referring
// to that entity, so the standard doesn't appear to say whether this is valid.
struct S s;
}
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