public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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
@ 2021-02-21  1:52 huili80 at gmail dot com
  2021-02-22 16:44 ` [Bug c++/99186] " m.cencora at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: huili80 at gmail dot com @ 2021-02-21  1:52 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-12-16 17:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-21  1:52 [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 huili80 at gmail dot com
2021-02-22 16:44 ` [Bug c++/99186] " m.cencora at gmail dot com
2021-08-12 21:33 ` pinskia at gcc dot gnu.org
2021-12-08 14:13 ` marxin at gcc dot gnu.org
2021-12-08 15:38 ` redi at gcc dot gnu.org
2021-12-08 15:49 ` redi at gcc dot gnu.org
2021-12-08 15:53 ` redi at gcc dot gnu.org
2023-12-13 20:57 ` cvs-commit at gcc dot gnu.org
2023-12-16 17:15 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).