The function in namespace X returns an enumerator from a locally defined enum class, via an auto deduced return type. That return value is then passed to an unqualified function, and on g++ (7.3, 8.2, trunk) it finds the function in namespace X. On clang, it gives an error for not finding the function.
I assume it has to do with ADL and the question of whether a function-local declared enum is in the function's containing namespace.
Which compiler is right, and why? (Standard citation appreciated.)
namespace X {
template <typename EnumT>
EnumT getA(EnumT) {
return EnumT::A;
}
enum class Foo { B, A, C };
auto getLocalEnumerator() {
enum class Bar { A, B, C };
return Bar::C;
}
}
int main() {
auto e1 = X::Foo::C; // unambiguously in namespace X
auto e2 = X::getLocalEnumerator(); // unsure what namespace this is
auto a1 = getA(e1); // obvious use of ADL
auto a2 = getA(e2); // clang: error, g++: ADL ok
}
live on godbolt: https://godbolt.org/g/w2DhDm
Thanks!
Aucun commentaire:
Enregistrer un commentaire