public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "huili80 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-99186-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2021-02-21  1:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-21  1:52 huili80 at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99186-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).