public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
@ 2021-04-27 18:44 davidfromonline at gmail dot com
  2021-04-28 12:30 ` [Bug c++/100295] " ppalka at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: davidfromonline at gmail dot com @ 2021-04-27 18:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100295
           Summary: Internal compiler error from generic lambda capturing
                    parameter pack and expanding it in if constexpr
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidfromonline at gmail dot com
  Target Milestone: ---

The following well-formed translation unit

```
template<typename... Ts>
void f(Ts... ts) {
        auto lambda = [=](auto x) {
                if constexpr (sizeof((..., ts), x) != 0) {
                        (..., ts);
                }
        };
        lambda(0);
}

void g() {
        f(0);
}
```

causes gcc to crash with

```
<source>: In instantiation of ‘f<int>(int)::<lambda(auto:1)> [with auto:1 =
int]’:
<source>:8:8:   required from ‘void f(Ts ...) [with Ts = {int}]’
<source>:12:3:   required from here
<source>:5:31: internal compiler error: trying to capture ‘ts#0’ in
instantiation of generic lambda
    5 |                         (..., ts);
      |                               ^~
0x9c9318 add_capture(tree_node*, tree_node*, tree_node*, bool, bool)
        ../../source/gcc/cp/lambda.c:637
0x9c9391 add_default_capture(tree_node*, tree_node*, tree_node*)
        ../../source/gcc/cp/lambda.c:697
0xaa68ef tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../source/gcc/cp/pt.c:20834
0xaa3ea8 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../source/gcc/cp/pt.c:20949
0xaaf3d7 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:19204
0xaae9d1 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18229
0xaae9d1 gen_elem_of_pack_expansion_instantiation
        ../../source/gcc/cp/pt.c:12568
0xaae9d1 tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*)
        ../../source/gcc/cp/pt.c:13233
0xaa163f tsubst_fold_expr_pack
        ../../source/gcc/cp/pt.c:12646
0xaa163f tsubst_unary_left_fold
        ../../source/gcc/cp/pt.c:12685
0xaa163f tsubst_copy
        ../../source/gcc/cp/pt.c:17343
0xaa56f2 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../source/gcc/cp/pt.c:20962
0xaaf3d7 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:19204
0xab11f9 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18274
0xab0aa3 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18595
0xab4503 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18564
0xab0aa3 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18595
0xab0aa3 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18595
0xab8308 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18229
0xab8308 instantiate_body
        ../../source/gcc/cp/pt.c:25921
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.
Compiler returned: 1
```

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
@ 2021-04-28 12:30 ` ppalka at gcc dot gnu.org
  2021-10-21  4:21 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-28 12:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed, looks like this never worked.

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
  2021-04-28 12:30 ` [Bug c++/100295] " ppalka at gcc dot gnu.org
@ 2021-10-21  4:21 ` pinskia at gcc dot gnu.org
  2021-10-21  4:22 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-21  4:21 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |benni.probst at gmx dot de

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 102866 has been marked as a duplicate of this bug. ***

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
  2021-04-28 12:30 ` [Bug c++/100295] " ppalka at gcc dot gnu.org
  2021-10-21  4:21 ` pinskia at gcc dot gnu.org
@ 2021-10-21  4:22 ` pinskia at gcc dot gnu.org
  2022-08-24  1:50 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-21  4:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 102778 has been marked as a duplicate of this bug. ***

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
                   ` (2 preceding siblings ...)
  2021-10-21  4:22 ` pinskia at gcc dot gnu.org
@ 2022-08-24  1:50 ` pinskia at gcc dot gnu.org
  2022-12-03  9:08 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-24  1:50 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |janezz55 at gmail dot com

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 106689 has been marked as a duplicate of this bug. ***

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
                   ` (3 preceding siblings ...)
  2022-08-24  1:50 ` pinskia at gcc dot gnu.org
@ 2022-12-03  9:08 ` pinskia at gcc dot gnu.org
  2022-12-15 21:03 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-03  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |onebit74 at gmail dot com

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 107955 has been marked as a duplicate of this bug. ***

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
                   ` (4 preceding siblings ...)
  2022-12-03  9:08 ` pinskia at gcc dot gnu.org
@ 2022-12-15 21:03 ` cvs-commit at gcc dot gnu.org
  2022-12-15 21:04 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-15 21:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 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:18499b9f848707aee42d810e99ac0a4c9788433c

commit r13-4730-g18499b9f848707aee42d810e99ac0a4c9788433c
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Dec 15 16:02:05 2022 -0500

    c++: extract_local_specs and unevaluated contexts [PR100295]

    Here during partial instantiation of the constexpr if, extra_local_specs
    walks the statement looking for local specializations within to capture.
    However, we're thwarted by the fact that 'ts' first appears inside an
    unevaluated context, and so the calls to process_outer_var_ref for its
    local specializations are a no-op.  And since we walk each tree exactly
    once, we end up not capturing the local specializations despite 'ts'
    later occurring in an evaluated context.

    This patch fixes this by making extract_local_specs walk evaluated
    contexts first before walking unevaluated contexts.  We could probably
    get away with not walking unevaluated contexts at all, but this approach
    seems more clearly safe.

            PR c++/100295
            PR c++/107579

    gcc/cp/ChangeLog:

            * pt.cc (el_data::skip_unevaluated_operands): New data member.
            (extract_locals_r): If skip_unevaluated_operands is true,
            don't walk into unevaluated contexts.
            (extract_local_specs): Walk the pattern twice, first with
            skip_unevaluated_operands true followed by it set to false.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1z/constexpr-if-lambda5.C: New test.

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
                   ` (5 preceding siblings ...)
  2022-12-15 21:03 ` cvs-commit at gcc dot gnu.org
@ 2022-12-15 21:04 ` ppalka at gcc dot gnu.org
  2022-12-19 16:54 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-12-15 21:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.3
             Status|NEW                         |ASSIGNED

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed on trunk so far

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
                   ` (6 preceding siblings ...)
  2022-12-15 21:04 ` ppalka at gcc dot gnu.org
@ 2022-12-19 16:54 ` cvs-commit at gcc dot gnu.org
  2023-02-17 13:24 ` ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-19 16:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

commit r12-8998-gcdc1a14be1182874ccf1ceb27ee5b67c5ce8c62d
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Dec 15 16:02:05 2022 -0500

    c++: extract_local_specs and unevaluated contexts [PR100295]

    Here during partial instantiation of the constexpr if, extra_local_specs
    walks the statement looking for local specializations within to capture.
    However, we're thwarted by the fact that 'ts' first appears inside an
    unevaluated context, and so the calls to process_outer_var_ref for its
    local specializations are a no-op.  And since we walk each tree exactly
    once, we end up not capturing the local specializations despite 'ts'
    later occurring in an evaluated context.

    This patch fixes this by making extract_local_specs walk evaluated
    contexts first before walking unevaluated contexts.  We could probably
    get away with not walking unevaluated contexts at all, but this approach
    seems more clearly safe.

            PR c++/100295
            PR c++/107579

    gcc/cp/ChangeLog:

            * pt.cc (el_data::skip_unevaluated_operands): New data member.
            (extract_locals_r): If skip_unevaluated_operands is true,
            don't walk into unevaluated contexts.
            (extract_local_specs): Walk the pattern twice, first with
            skip_unevaluated_operands true followed by it set to false.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1z/constexpr-if-lambda5.C: New test.

    (cherry picked from commit 18499b9f848707aee42d810e99ac0a4c9788433c)

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
                   ` (7 preceding siblings ...)
  2022-12-19 16:54 ` cvs-commit at gcc dot gnu.org
@ 2023-02-17 13:24 ` ppalka at gcc dot gnu.org
  2023-05-22  3:12 ` cvs-commit at gcc dot gnu.org
  2023-05-22  3:15 ` ppalka at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-02-17 13:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |12.2.1, 13.0
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #9 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12.3/13

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
                   ` (8 preceding siblings ...)
  2023-02-17 13:24 ` ppalka at gcc dot gnu.org
@ 2023-05-22  3:12 ` cvs-commit at gcc dot gnu.org
  2023-05-22  3:15 ` ppalka at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-22  3:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 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:58d2a4cdbbafa4431eb9cff3778099d185f9f391

commit r11-10804-g58d2a4cdbbafa4431eb9cff3778099d185f9f391
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Dec 15 16:02:05 2022 -0500

    c++: extract_local_specs and unevaluated contexts [PR100295]

    Here during partial instantiation of the constexpr if, extra_local_specs
    walks the statement looking for local specializations within to capture.
    However, we're thwarted by the fact that 'ts' first appears inside an
    unevaluated context, and so the calls to process_outer_var_ref for its
    local specializations are a no-op.  And since we walk each tree exactly
    once, we end up not capturing the local specializations despite 'ts'
    later occurring in an evaluated context.

    This patch fixes this by making extract_local_specs walk evaluated
    contexts first before walking unevaluated contexts.  We could probably
    get away with not walking unevaluated contexts at all, but this approach
    seems more clearly safe.

            PR c++/100295
            PR c++/107579

    gcc/cp/ChangeLog:

            * pt.c (el_data::skip_unevaluated_operands): New data member.
            (extract_locals_r): If skip_unevaluated_operands is true,
            don't walk into unevaluated contexts.
            (extract_local_specs): Walk the pattern twice, first with
            skip_unevaluated_operands true followed by it set to false.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1z/constexpr-if-lambda5.C: New test.

    (cherry picked from commit 18499b9f848707aee42d810e99ac0a4c9788433c)

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

* [Bug c++/100295] Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr
  2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
                   ` (9 preceding siblings ...)
  2023-05-22  3:12 ` cvs-commit at gcc dot gnu.org
@ 2023-05-22  3:15 ` ppalka at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-22  3:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.3                        |11.4

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

end of thread, other threads:[~2023-05-22  3:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 18:44 [Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr davidfromonline at gmail dot com
2021-04-28 12:30 ` [Bug c++/100295] " ppalka at gcc dot gnu.org
2021-10-21  4:21 ` pinskia at gcc dot gnu.org
2021-10-21  4:22 ` pinskia at gcc dot gnu.org
2022-08-24  1:50 ` pinskia at gcc dot gnu.org
2022-12-03  9:08 ` pinskia at gcc dot gnu.org
2022-12-15 21:03 ` cvs-commit at gcc dot gnu.org
2022-12-15 21:04 ` ppalka at gcc dot gnu.org
2022-12-19 16:54 ` cvs-commit at gcc dot gnu.org
2023-02-17 13:24 ` ppalka at gcc dot gnu.org
2023-05-22  3:12 ` cvs-commit at gcc dot gnu.org
2023-05-22  3:15 ` 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).