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

            Bug ID: 103346
           Summary: ICE on template specialization via alias template with
                    a non-type parameter pack, and fold expression on
                    lambda calls
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ap.vanzanten at gmail dot com
  Target Milestone: ---

Command: g++ -std=c++20 <code file>

Code:
----

struct Item {};

template <typename T, T... ts>
struct Sequence;

template <Item... items>
using ItemSequence = Sequence<Item, items...>;

template <Item... items>
constexpr auto f() {
  constexpr auto l = [](Item item) { return item; };
  return ItemSequence<l(items)...>{};
}

----

Output:
----

<source>: In substitution of 'template<Item ...items> using ItemSequence =
Sequence<Item, (const Item)items ...> [with Item ...items = {f::l((const
Item)items)...}]':
<source>:12:34:   required from here
<source>:7:37: internal compiler error: Segmentation fault
    7 | using ItemSequence = Sequence<Item, items...>;
      |                                     ^~~~~
0x1786229 internal_error(char const*, ...)
        ???:0
0xfa6740 strip_array_types(tree_node*)
        ???:0
0x82f438 cp_type_quals(tree_node const*)
        ???:0
0x7e8a1b tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x7ef14a tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x7ef72c tsubst_argument_pack(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x7ef12c tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x7dd7cc tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x7dd8a7 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x7f40b2 instantiate_template(tree_node*, tree_node*, int)
        ???:0
0x7dde4d tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x7e6702 lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int, int)
        ???:0
0x80a52d finish_template_type(tree_node*, tree_node*, int)
        ???:0
0x7c47db c_parse_file()
        ???:0
0x896762 c_common_parse_file()
        ???:0
Please submit a full bug report,
...

----

Note the issue is not present when moving the lambda 'l' out of the function
'f' (into global scope), or when removing the 'ItemSequence' alias, and simply
using 'Sequence<Item, items...>' directly.

See also https://godbolt.org/z/Yqnnod4W6 for a live example.
  • [Bug c++/103346] New: ICE on te... ap.vanzanten at gmail dot com via Gcc-bugs

Reply via email to