public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100138] New: ICE with constructor constrained (C++20 Concepts) by parameter pack length
@ 2021-04-18 23:00 pkeir at outlook dot com
  2021-04-19  2:07 ` [Bug c++/100138] " ppalka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: pkeir at outlook dot com @ 2021-04-18 23:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100138
           Summary: ICE with constructor constrained (C++20 Concepts) by
                    parameter pack length
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pkeir at outlook dot com
  Target Milestone: ---

Created attachment 50624
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50624&action=edit
The C++ file producing the ICE

Compiling the code below with `-c -std=c++20` produces an ICE. 

template <int N = 1>
struct Foo
{
  template <typename ...Ts>
  Foo(Ts... xs) requires(sizeof...(xs)==N) {}
};

void bar()
{
  Foo x{64};
}

As a workaround, using Ts rather than xs within the requires clause avoids the
ICE. The error message is below:

constrained_ctor.hpp: In substitution of ‘template<int N, class ... Ts> Foo(Ts
...)-> Foo<N> requires  sizeof ... ((Foo<N>::__ct ::xs ...)) == N [with int N =
1; Ts = {int}]’:
constrained_ctor.hpp:10:11:   required from here
constrained_ctor.hpp:5:26: internal compiler error: Segmentation fault
    5 |   Foo(Ts... xs) requires(sizeof...(xs)==N) {}
      |                          ^~~~~~~~~~~~~
0x10d0e8f crash_signal
        ../../gcc/toplev.c:327
0x950d49 hash_table<hash_map<tree_node*, tree_node*,
simple_hashmap_traits<default_hash_traits<tree_node*>, tree_node*>
>::hash_entry, false, xcallocator>::find_slot_with_hash(tree_node* const&,
unsigned int, insert_option)
        ../../gcc/hash-table.h:963
0xac055d hash_map<tree_node*, tree_node*,
simple_hashmap_traits<default_hash_traits<tree_node*>, tree_node*>
>::put(tree_node* const&, tree_node* const&)
        ../../gcc/hash-map.h:166
0xac055d register_local_specialization(tree_node*, tree_node*)
        ../../gcc/cp/pt.c:2004
0xad21e1 gen_elem_of_pack_expansion_instantiation
        ../../gcc/cp/pt.c:12496
0xad21e1 tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/cp/pt.c:13173
0xac63be tsubst_copy
        ../../gcc/cp/pt.c:16925
0xac7ca4 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc/cp/pt.c:20896
0xac7ad3 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc/cp/pt.c:19856
0xad3128 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc/cp/pt.c:19144
0x95a455 satisfy_atom
        ../../gcc/cp/constraint.cc:2984
0x95a455 satisfy_constraint_r
        ../../gcc/cp/constraint.cc:3047
0x95a779 satisfy_normalized_constraints
        ../../gcc/cp/constraint.cc:3069
0x957d7e satisfy_declaration_constraints
        ../../gcc/cp/constraint.cc:3277
0x957d7e constraint_satisfaction_value
        ../../gcc/cp/constraint.cc:3297
0x95a810 constraints_satisfied_p(tree_node*, tree_node*)
        ../../gcc/cp/constraint.cc:3334
0xaf98a5 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
        ../../gcc/cp/pt.c:21632
0x9053fd add_template_candidate_real
        ../../gcc/cp/call.c:3456
0x905eda add_template_candidate
        ../../gcc/cp/call.c:3541
0x905eda add_candidates
        ../../gcc/cp/call.c:6031
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/100138] ICE with constructor constrained (C++20 Concepts) by parameter pack length
  2021-04-18 23:00 [Bug c++/100138] New: ICE with constructor constrained (C++20 Concepts) by parameter pack length pkeir at outlook dot com
@ 2021-04-19  2:07 ` ppalka at gcc dot gnu.org
  2021-05-06 15:37 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-19  2:07 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-04-19
     Ever confirmed|0                           |1
                 CC|                            |ppalka at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed.  Interestingly, avoiding CTAD by replacing 'Foo' with 'Foo<>` in the
declaration of 'x' seems to be another workaround.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/100138] ICE with constructor constrained (C++20 Concepts) by parameter pack length
  2021-04-18 23:00 [Bug c++/100138] New: ICE with constructor constrained (C++20 Concepts) by parameter pack length pkeir at outlook dot com
  2021-04-19  2:07 ` [Bug c++/100138] " ppalka at gcc dot gnu.org
@ 2021-05-06 15:37 ` ppalka at gcc dot gnu.org
  2021-05-11  2:39 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-05-06 15:37 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/100138] ICE with constructor constrained (C++20 Concepts) by parameter pack length
  2021-04-18 23:00 [Bug c++/100138] New: ICE with constructor constrained (C++20 Concepts) by parameter pack length pkeir at outlook dot com
  2021-04-19  2:07 ` [Bug c++/100138] " ppalka at gcc dot gnu.org
  2021-05-06 15:37 ` ppalka at gcc dot gnu.org
@ 2021-05-11  2:39 ` cvs-commit at gcc dot gnu.org
  2021-07-16 22:49 ` cvs-commit at gcc dot gnu.org
  2021-07-16 22:51 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-11  2:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:e7a9f085ffd34b0d7bc4b803c182b41494f609aa

commit r12-701-ge7a9f085ffd34b0d7bc4b803c182b41494f609aa
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon May 10 22:33:04 2021 -0400

    c++: fn parm pack expansion inside constraint [PR100138]

    This PR is about CTAD but the underlying problems are more general;
    CTAD is a good trigger for them because of the necessary substitution
    into constraints that deduction guide generation entails.

    In the testcase below, when generating the implicit deduction guide for
    the constrained constructor template for A, we substitute the generic
    flattening map 'tsubst_args' into the constructor's constraints.  During
    this substitution, tsubst_pack_expansion returns a rebuilt pack
    expansion for sizeof...(xs), but doesn't carry over the
    PACK_EXPANSION_LOCAL_P (and PACK_EXPANSION_SIZEOF_P) flag from the
    original tree to the rebuilt one.  The flag is otherwise unset on the
    original tree but gets set for the rebuilt tree from make_pack_expansion
    since at_function_scope_p() is true (we're inside main).  This leads to
    a crash during satisfaction when substituting into the pack expansion
    because we don't have local_specializations set up (and it'd be set up
    for us if PACK_EXPANSION_LOCAL_P is unset)

    Similarly, tsubst_constraint needs to set cp_unevaluated so that the
    substitution performed therein doesn't rely on local_specializations.
    This avoids a crash during CTAD for C below.

    gcc/cp/ChangeLog:

            PR c++/100138
            * constraint.cc (tsubst_constraint): Set up cp_unevaluated.
            (satisfy_atom): Set up iloc_sentinel before calling
            cxx_constant_value.
            * pt.c (tsubst_pack_expansion): When returning a rebuilt pack
            expansion, carry over PACK_EXPANSION_LOCAL_P and
            PACK_EXPANSION_SIZEOF_P from the original pack expansion.

    gcc/testsuite/ChangeLog:

            PR c++/100138
            * g++.dg/cpp2a/concepts-ctad4.C: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/100138] ICE with constructor constrained (C++20 Concepts) by parameter pack length
  2021-04-18 23:00 [Bug c++/100138] New: ICE with constructor constrained (C++20 Concepts) by parameter pack length pkeir at outlook dot com
                   ` (2 preceding siblings ...)
  2021-05-11  2:39 ` cvs-commit at gcc dot gnu.org
@ 2021-07-16 22:49 ` cvs-commit at gcc dot gnu.org
  2021-07-16 22:51 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-16 22:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:2e63d08cb9bc001232734eed32e4bc3814a279a9

commit r11-8761-g2e63d08cb9bc001232734eed32e4bc3814a279a9
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon May 10 22:33:04 2021 -0400

    c++: fn parm pack expansion inside constraint [PR100138]

    This PR is about CTAD but the underlying problems are more general;
    CTAD is a good trigger for them because of the necessary substitution
    into constraints that deduction guide generation entails.

    In the testcase below, when generating the implicit deduction guide for
    the constrained constructor template for A, we substitute the generic
    flattening map 'tsubst_args' into the constructor's constraints.  During
    this substitution, tsubst_pack_expansion returns a rebuilt pack
    expansion for sizeof...(xs), but doesn't carry over the
    PACK_EXPANSION_LOCAL_P (and PACK_EXPANSION_SIZEOF_P) flag from the
    original tree to the rebuilt one.  The flag is otherwise unset on the
    original tree but gets set for the rebuilt tree from make_pack_expansion
    since at_function_scope_p() is true (we're inside main).  This leads to
    a crash during satisfaction when substituting into the pack expansion
    because we don't have local_specializations set up (and it'd be set up
    for us if PACK_EXPANSION_LOCAL_P is unset)

    Similarly, tsubst_constraint needs to set cp_unevaluated so that the
    substitution performed therein doesn't rely on local_specializations.
    This avoids a crash during CTAD for C below.

    gcc/cp/ChangeLog:

            PR c++/100138
            * constraint.cc (tsubst_constraint): Set up cp_unevaluated.
            (satisfy_atom): Set up iloc_sentinel before calling
            cxx_constant_value.
            * pt.c (tsubst_pack_expansion): When returning a rebuilt pack
            expansion, carry over PACK_EXPANSION_LOCAL_P and
            PACK_EXPANSION_SIZEOF_P from the original pack expansion.

    gcc/testsuite/ChangeLog:

            PR c++/100138
            * g++.dg/cpp2a/concepts-ctad4.C: New test.

    (cherry picked from commit e7a9f085ffd34b0d7bc4b803c182b41494f609aa)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/100138] ICE with constructor constrained (C++20 Concepts) by parameter pack length
  2021-04-18 23:00 [Bug c++/100138] New: ICE with constructor constrained (C++20 Concepts) by parameter pack length pkeir at outlook dot com
                   ` (3 preceding siblings ...)
  2021-07-16 22:49 ` cvs-commit at gcc dot gnu.org
@ 2021-07-16 22:51 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-07-16 22:51 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |11.2

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 11.2 and 12.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-16 22:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-18 23:00 [Bug c++/100138] New: ICE with constructor constrained (C++20 Concepts) by parameter pack length pkeir at outlook dot com
2021-04-19  2:07 ` [Bug c++/100138] " ppalka at gcc dot gnu.org
2021-05-06 15:37 ` ppalka at gcc dot gnu.org
2021-05-11  2:39 ` cvs-commit at gcc dot gnu.org
2021-07-16 22:49 ` cvs-commit at gcc dot gnu.org
2021-07-16 22:51 ` ppalka at gcc dot gnu.org

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).