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

            Bug ID: 103672
           Summary: using with template<template<class...> class> causes
                    internal compiler error
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: turtlefight at ymail dot com
  Target Milestone: ---

The following example results in an internal compiler error.
It does compile fine with clang and msvc.

Example Code:

#include <functional>
#include <memory>

template<class T>
struct unique {
    auto operator()(auto&&... args) {
        return std::make_unique<T>(std::forward<decltype(args)>(args)...);
    }
};

template<template<class...> class T, class... Args>
using deduced_type = decltype(T{std::declval<Args>()...});

template<template<class> class F, template<class...> class T, class... Args>
auto make(Args&&... args) {
    return F<deduced_type<T, Args...>>{}(std::forward<Args>(args)...);
}

template<class A, class B>
struct Foo { Foo(A,B) {} };


int main(){
    auto foo_unique = make<unique, Foo>(1, 2);
}


Full Error Message:
<source>: In instantiation of 'auto make(Args&& ...) [with F = unique; T = Foo;
Args = {int, int}]':
<source>:24:40:   required from here
<source>:16:41: internal compiler error: in tsubst, at cp/pt.c:15632
   16 |     return F<deduced_type<T, Args...>>{}(std::forward<Args>(args)...);
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0x21004e9 internal_error(char const*, ...)
        ???:0
0x7e96eb fancy_abort(char const*, int, char const*)
        ???:0
0xa5fde7 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xa5d3af tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xa89b76 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xa5d954 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xa5eb8d tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xa63a47 instantiate_decl(tree_node*, bool, bool)
        ???:0
0x904ebe maybe_instantiate_decl(tree_node*)
        ???:0
0x906980 mark_used(tree_node*, int)
        ???:0
0x819197 build_new_function_call(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        ???:0
0xaca89c finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xa29b8d c_parse_file()
        ???:0
0xbb6bb2 c_common_parse_file()
        ???:0


Godbolt Example: https://godbolt.org/z/rd4PdYrq8


What's interesting is that the code compiles without problems if a using
declaration is not used, e.g.:

template<template<class> class F, template<class...> class T, class... Args>
auto make(Args&&... args) {
    return
F<decltype(T{std::declval<Args>()...})>{}(std::forward<Args>(args)...);
}


Godbolt Example: https://godbolt.org/z/Pd3Mjs8rG

Reply via email to