public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "turtlefight at ymail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/103672] New: using with template<template<class...> class> causes internal compiler error
Date: Sun, 12 Dec 2021 18:51:49 +0000	[thread overview]
Message-ID: <bug-103672-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2021-12-12 18:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-12 18:51 turtlefight at ymail dot com [this message]
2021-12-13 11:59 ` [Bug c++/103672] [10/11/12 Regression] " redi at gcc dot gnu.org
2022-01-04  9:47 ` rguenth at gcc dot gnu.org
2022-01-13 15:28 ` ppalka at gcc dot gnu.org
2022-01-20 14:26 ` cvs-commit at gcc dot gnu.org
2022-01-20 14:30 ` [Bug c++/103672] [10/11 " ppalka at gcc dot gnu.org
2022-05-11 17:48 ` ppalka at gcc dot gnu.org
2022-06-28 10:47 ` jakub at gcc dot gnu.org
2023-05-21 15:12 ` 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-103672-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).