https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99186
Bug ID: 99186 Summary: std::tuple compilation error when elements are specializations of template class declared with template < auto E > syntax with E being a enumerator of a enum Product: gcc Version: 8.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: huili80 at gmail dot com Target Milestone: --- Example code below: #include <type_traits> #include <tuple> enum class E1 {a}; enum class E2 {b,c}; template < auto > struct S { int i; }; static_assert(not std::is_same_v<S<E1::a>,S<E2::b>>); struct D : S<E1::a>, S<E2::b> {}; int main() { D d; d.S<E1::a>::i = 0; std::tuple<S<E1::a>,S<E2::b>,S<E2::c>> x; std::get<0>(x).i = 0; std::get<S<E2::c>>(x).i = 0; std::get<S<E2::b>>(x).i = 0; // does not compile return 0; } GCC 10.2 c++17 gives the following error: In file included from main.cpp:2: /usr/local/include/c++/10.2.0/tuple: In instantiation of 'constexpr _Tp& std::get(std::tuple<_UTypes ...>&) [with _Tp = S<E2::b> _Types = {S<E1::a>, S<E2::b>, S<E2::c>}]': main.cpp:27:24: required from here /usr/local/include/c++/10.2.0/tuple:1339:37: error: no matching function for call to '__get_helper2<S<E2::b> >(std::tuple<S<E1::a>, S<E2::b>, S<E2::c> >&)' 1339 | { return std::__get_helper2<_Tp>(__t); } | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~ /usr/local/include/c++/10.2.0/tuple:1327:5: note: candidate: 'template<class _Head, long unsigned int __i, class ... _Tail> constexpr _Head& std::__get_helper2(std::_Tuple_impl<__i, _Head, _Tail ...>&)' 1327 | __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept | ^~~~~~~~~~~~~ /usr/local/include/c++/10.2.0/tuple:1327:5: note: template argument deduction/substitution failed: /usr/local/include/c++/10.2.0/tuple:1339:37: note: 'std::_Tuple_impl<__i, S<E2::b>, _Tail ...>' is an ambiguous base class of 'std::tuple<S<E1::a>, S<E2::b>, S<E2::c> >' 1339 | { return std::__get_helper2<_Tp>(__t); } | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~ /usr/local/include/c++/10.2.0/tuple:1332:5: note: candidate: 'template<class _Head, long unsigned int __i, class ... _Tail> constexpr const _Head& std::__get_helper2(const std::_Tuple_impl<__i, _Head, _Tail ...>&)' 1332 | __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept | ^~~~~~~~~~~~~ /usr/local/include/c++/10.2.0/tuple:1332:5: note: template argument deduction/substitution failed: /usr/local/include/c++/10.2.0/tuple:1339:37: note: 'const std::_Tuple_impl<__i, S<E2::b>, _Tail ...>' is an ambiguous base class of 'std::tuple<S<E1::a>, S<E2::b>, S<E2::c> >' 1339 | { return std::__get_helper2<_Tp>(__t); } | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~ Output: If E1 and E2 had been non-scoped enums, the code results in the same compiler error. It's curious that the error mentions ambiguous base classes in std::tuple's implementation. Given that std::get<S<E2::c>>(x) compiles fine, I speculated that the compiler may have incorrectly thought that S<E1::a> and S<E2::b> are the same type since E1::a and E2::b have the same numeric value (zero). However, that speculation is proven wrong by other parts of the example code clearly shows that the compiler does NOT think S<E1::a> and S<E2::b> are the same type, e.g., the static_assert that S<E1::a> and S<E2::b> are not the same type, and that even though struct D inherits from both S<E1::a>, S<E2::b>, we can access its base S<E1::a>'s member variable.