From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CBF193857804; Sun, 21 Feb 2021 01:52:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBF193857804 From: "huili80 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99186] New: 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 Date: Sun, 21 Feb 2021 01:52:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 8.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: huili80 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Feb 2021 01:52:41 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99186 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 #include enum class E1 {a}; enum class E2 {b,c}; template < auto > struct S { int i; }; static_assert(not std::is_same_v,S>); struct D : S, S {}; int main() { D d; d.S::i =3D 0; std::tuple,S,S> x; std::get<0>(x).i =3D 0; std::get>(x).i =3D 0; std::get>(x).i =3D 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 =3D S _Types =3D {S, S, S}]': 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 >(std::tuple, S, S >= &)' 1339 | { return std::__get_helper2<_Tp>(__t); } | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~ /usr/local/include/c++/10.2.0/tuple:1327:5: note: candidate: 'template 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, _Tail ...>' is an ambiguous base class of 'std::tuple, S, S >' 1339 | { return std::__get_helper2<_Tp>(__t); } | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~ /usr/local/include/c++/10.2.0/tuple:1332:5: note: candidate: 'template 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, _Tail ...>' is an ambiguous base class of 'std::tuple, S, S >' 1339 | { return std::__get_helper2<_Tp>(__t); } | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~ Output: If E1 and E2 had been non-scoped enums, the code results in the same compil= er error. It's curious that the error mentions ambiguous base classes in std::tuple's implementation. Given that std::get>(x) compiles fine, I speculated that the compiler may have incorrectly thought that S and S a= re 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 and S are the same type, e.g., the static_assert that S and S are not the s= ame type, and that even though struct D inherits from both S, S, = we can access its base S's member variable.=