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 via email to