public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "federico at kircheis dot it" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/113349] New: internal compiler error: in tsubst
Date: Fri, 12 Jan 2024 09:16:38 +0000	[thread overview]
Message-ID: <bug-113349-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113349

            Bug ID: 113349
           Summary: internal compiler error: in tsubst
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico at kircheis dot it
  Target Milestone: ---

While trying to destructure a tuple, I got this internal compiler error

----
<source>: In substitution of 'template<class T> template<long unsigned int N>
using types<T, decltype ((<lambda>(), void()))>::el = std::tuple_element_t<N,
decltype (<lambda>())> [with long unsigned int N = 1; T = s]':
<source>:36:50:   required from here
   36 | static_assert(std::is_same_v<char*, types<s>::el<1>>);
      |                                                  ^
<source>:7:28: internal compiler error: in tsubst, at cp/pt.cc:16312
    7 | #define MAKE_TUPLE(V, ...) []{\
      |                            ^~~~
    8 |     auto [ __VA_ARGS__ ] = makeV<V>(); \
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    9 |     return std::make_tuple( __VA_ARGS__);\
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   10 | }()
      | ~                           
<source>:19:26: note: in expansion of macro 'MAKE_TUPLE'
   19 | struct types<T, decltype(MAKE_TUPLE(T, e0, e1, e2), void())> {
      |                          ^~~~~~~~~~
0x2640f8c internal_error(char const*, ...)
        ???:0
0xa502dd fancy_abort(char const*, int, char const*)
        ???:0
0xc92c62 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xca446c tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xc93417 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xc99729 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xc7c365 instantiate_template(tree_node*, tree_node*, int)
        ???:0
0xc9420c tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xc914dc lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int, int)
        ???:0
0xccd98f finish_template_type(tree_node*, tree_node*, int)
        ???:0
0xc51fda c_parse_file()
        ???:0
0xda59d9 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
----

The code looks like

----
#include <tuple>
#include <utility>

template <class V>
V makeV();

#define MAKE_TUPLE(V, ...) []{\
    auto [ __VA_ARGS__ ] = makeV<V>(); \
    return std::make_tuple( __VA_ARGS__);\
}()


template <typename T, typename = void>
struct types{
    using type = void;
};

template <typename T>
struct types<T, decltype(MAKE_TUPLE(T, e0, e1, e2), void())> {
    template<std::size_t N>
    using el = std::tuple_element_t<N, decltype(MAKE_TUPLE(T, e0, e1, e2))>;
};
/*
template <typename T>
struct types<T, decltype(MAKE_TUPLE(T, e1), void())> {
    template<std::size_t N>
    using el = std::tuple_element_t<N, decltype(MAKE_TUPLE(T, e1))>;
};
*/
struct s{
    int& i;
    char* b;
    float f;
};
//static_assert(std::is_same_v<int&, types<s>::el<0>>); // fails
static_assert(std::is_same_v<char*, types<s>::el<1>>);
static_assert(std::is_same_v<float, types<s>::el<2>>);
----

This code compiles fine with clang and MSVC, and is, to the best of my
knowledge, valid C++

Online example with latest gcc (and clang msvc too)

https://godbolt.org/z/sPxK5avEW

             reply	other threads:[~2024-01-12  9:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-12  9:16 federico at kircheis dot it [this message]
2024-01-12  9:28 ` [Bug c++/113349] " pinskia at gcc dot gnu.org
2024-01-18 17:51 ` mpolacek at gcc dot gnu.org
2024-01-18 18:48 ` mpolacek at gcc dot gnu.org
2024-01-18 19:01 ` mpolacek at gcc dot gnu.org
2024-01-18 19:03 ` [Bug c++/113349] [11/12/13/14 Regression] " mpolacek 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-113349-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).