public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108219] New: requirement fails on a valid expression
@ 2022-12-24 22:04 vanyacpp at gmail dot com
  2022-12-24 23:33 ` [Bug c++/108219] [12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: vanyacpp at gmail dot com @ 2022-12-24 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108219
           Summary: requirement fails on a valid expression
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
  Target Milestone: ---

This code compiles OK on clang, MSVC and GCC prior to 12:

template <typename T>
concept test = requires
{
    new T[1]{{ 42 }};
};

struct foobar
{
    foobar(int);
};

int main()
{
    static_assert(test<foobar>);
    new foobar[1]{{ 42 }};
}

But on GCC 12 it produces an error:

<source>:14:19: error: static assertion failed
   14 |     static_assert(test<foobar>);
      |                   ^~~~~~~~~~~~
<source>:14:19: note: constraints not satisfied
<source>:2:9:   required by the constraints of 'template<class T> concept test'
<source>:2:16:   in requirements  [with T = foobar]
<source>:4:5: note: the required expression 'new T(1)' is invalid, because
    4 |     new T[1]{{ 42 }};
      |     ^~~~~~~~~~~~~~~~
<source>:4:5: error: could not convert '<brace-enclosed initializer list>()'
from '<brace-enclosed initializer list>' to 'foobar'
    4 |     new T[1]{{ 42 }};
      |     ^~~~~~~~~~~~~~~~
      |     |
      |     <brace-enclosed initializer list>

I believe the error is incorrect and that this is a regression in GCC 12.

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

* [Bug c++/108219] [12/13 Regression] requirement fails on a valid expression
  2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
@ 2022-12-24 23:33 ` pinskia at gcc dot gnu.org
  2022-12-27 12:35 ` [Bug c++/108219] [12/13 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569 marxin at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-24 23:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |11.3.0
   Last reconfirmed|                            |2022-12-24
   Target Milestone|---                         |12.3
           Keywords|                            |needs-bisection,
                   |                            |rejects-valid
     Ever confirmed|0                           |1
            Summary|requirement fails on a      |[12/13 Regression]
                   |valid expression            |requirement fails on a
                   |                            |valid expression
      Known to fail|                            |12.1.0
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/108219] [12/13 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569
  2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
  2022-12-24 23:33 ` [Bug c++/108219] [12/13 Regression] " pinskia at gcc dot gnu.org
@ 2022-12-27 12:35 ` marxin at gcc dot gnu.org
  2023-01-09 13:42 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-27 12:35 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org
           Keywords|needs-bisection             |
            Summary|[12/13 Regression]          |[12/13 Regression]
                   |requirement fails on a      |requirement fails on a
                   |valid expression            |valid expression since
                   |                            |r12-5253-g4df7f8c79835d569

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r12-5253-g4df7f8c79835d569.

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

* [Bug c++/108219] [12/13 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569
  2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
  2022-12-24 23:33 ` [Bug c++/108219] [12/13 Regression] " pinskia at gcc dot gnu.org
  2022-12-27 12:35 ` [Bug c++/108219] [12/13 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569 marxin at gcc dot gnu.org
@ 2023-01-09 13:42 ` rguenth at gcc dot gnu.org
  2023-02-22 17:19 ` ppalka at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-09 13:42 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug c++/108219] [12/13 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569
  2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
                   ` (2 preceding siblings ...)
  2023-01-09 13:42 ` rguenth at gcc dot gnu.org
@ 2023-02-22 17:19 ` ppalka at gcc dot gnu.org
  2023-03-01 19:09 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-02-22 17:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug c++/108219] [12/13 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569
  2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
                   ` (3 preceding siblings ...)
  2023-02-22 17:19 ` ppalka at gcc dot gnu.org
@ 2023-03-01 19:09 ` cvs-commit at gcc dot gnu.org
  2023-03-01 19:11 ` [Bug c++/108219] [12 " ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-01 19:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 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:096f034a8f5df41f610e62c1592fb90a3f551cd5

commit r13-6395-g096f034a8f5df41f610e62c1592fb90a3f551cd5
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Mar 1 14:09:37 2023 -0500

    c++: unevaluated array new-expr size constantness [PR108219]

    Here we're mishandling the unevaluated array new-expressions due to a
    supposed non-constant array size ever since r12-5253-g4df7f8c79835d569
    made us no longer perform constant evaluation of non-manifestly-constant
    expressions within unevaluated contexts.  This shouldn't make a difference
    here since the array sizes are constant literals, except they're expressed
    as NON_LVALUE_EXPR location wrappers around INTEGER_CST, wrappers which
    used to get stripped as part of constant evaluation and now no longer do.
    Moreover it means build_vec_init can't constant fold the MINUS_EXPR
    'maxindex' passed from build_new_1 when in an unevaluated context (since
    it tries reducing it via maybe_constant_value called with mce_unknown).

    This patch fixes these issues by making maybe_constant_value (and
    fold_non_dependent_expr) try folding an unevaluated non-manifestly-constant
    operand via fold(), as long as it simplifies to a simple constant, rather
    than doing no simplification at all.  This covers e.g. simple arithmetic
    and casts including stripping of location wrappers around INTEGER_CST.

    In passing, this patch also fixes maybe_constant_value to avoid constant
    evaluating an unevaluated operand when called with mce_false, by adjusting
    the early exit test appropriately.

    Co-authored-by: Jason Merrill <jason@redhat.com>

            PR c++/108219
            PR c++/108218

    gcc/cp/ChangeLog:

            * constexpr.cc (fold_to_constant): Define.
            (maybe_constant_value): Move up early exit test for unevaluated
            operands.  Try reducing an unevaluated operand to a constant via
            fold_to_constant.
            (fold_non_dependent_expr_template): Add early exit test for
            CONSTANT_CLASS_P nodes.  Try reducing an unevaluated operand
            to a constant via fold_to_constant.
            * cp-tree.h (fold_to_constant): Declare.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/new6.C: New test.
            * g++.dg/cpp2a/concepts-new1.C: New test.

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

* [Bug c++/108219] [12 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569
  2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
                   ` (4 preceding siblings ...)
  2023-03-01 19:09 ` cvs-commit at gcc dot gnu.org
@ 2023-03-01 19:11 ` ppalka at gcc dot gnu.org
  2023-03-03  9:35 ` vanyacpp at gmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-03-01 19:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |13.0
            Summary|[12/13 Regression]          |[12 Regression] requirement
                   |requirement fails on a      |fails on a valid expression
                   |valid expression since      |since
                   |r12-5253-g4df7f8c79835d569  |r12-5253-g4df7f8c79835d569

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 13 so far

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

* [Bug c++/108219] [12 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569
  2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
                   ` (5 preceding siblings ...)
  2023-03-01 19:11 ` [Bug c++/108219] [12 " ppalka at gcc dot gnu.org
@ 2023-03-03  9:35 ` vanyacpp at gmail dot com
  2023-04-28 22:13 ` cvs-commit at gcc dot gnu.org
  2023-04-28 22:16 ` ppalka at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: vanyacpp at gmail dot com @ 2023-03-03  9:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Ivan Sorokin <vanyacpp at gmail dot com> ---
(In reply to Patrick Palka from comment #4)
> Fixed for GCC 13 so far

Thank you very much!

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

* [Bug c++/108219] [12 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569
  2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
                   ` (6 preceding siblings ...)
  2023-03-03  9:35 ` vanyacpp at gmail dot com
@ 2023-04-28 22:13 ` cvs-commit at gcc dot gnu.org
  2023-04-28 22:16 ` ppalka at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-28 22:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 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:73e86b6766cc92aa8c18cc987bf95929c4ea0672

commit r12-9492-g73e86b6766cc92aa8c18cc987bf95929c4ea0672
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Mar 1 14:09:37 2023 -0500

    c++: unevaluated array new-expr size constantness [PR108219]

    Here we're mishandling the unevaluated array new-expressions due to a
    supposed non-constant array size ever since r12-5253-g4df7f8c79835d569
    made us no longer perform constant evaluation of non-manifestly-constant
    expressions within unevaluated contexts.  This shouldn't make a difference
    here since the array sizes are constant literals, except they're expressed
    as NON_LVALUE_EXPR location wrappers around INTEGER_CST, wrappers which
    used to get stripped as part of constant evaluation and now no longer do.
    Moreover it means build_vec_init can't constant fold the MINUS_EXPR
    'maxindex' passed from build_new_1 when in an unevaluated context (since
    it tries reducing it via maybe_constant_value called with mce_unknown).

    This patch fixes these issues by making maybe_constant_value (and
    fold_non_dependent_expr) try folding an unevaluated non-manifestly-constant
    operand via fold(), as long as it simplifies to a simple constant, rather
    than doing no simplification at all.  This covers e.g. simple arithmetic
    and casts including stripping of location wrappers around INTEGER_CST.

    In passing, this patch also fixes maybe_constant_value to avoid constant
    evaluating an unevaluated operand when called with mce_false, by adjusting
    the early exit test appropriately.

    Co-authored-by: Jason Merrill <jason@redhat.com>

            PR c++/108219
            PR c++/108218

    gcc/cp/ChangeLog:

            * constexpr.cc (fold_to_constant): Define.
            (maybe_constant_value): Move up early exit test for unevaluated
            operands.  Try reducing an unevaluated operand to a constant via
            fold_to_constant.
            (fold_non_dependent_expr_template): Add early exit test for
            CONSTANT_CLASS_P nodes.  Try reducing an unevaluated operand
            to a constant via fold_to_constant.
            * cp-tree.h (fold_to_constant): Declare.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/new6.C: New test.
            * g++.dg/cpp2a/concepts-new1.C: New test.

    (cherry picked from commit 096f034a8f5df41f610e62c1592fb90a3f551cd5)

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

* [Bug c++/108219] [12 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569
  2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
                   ` (7 preceding siblings ...)
  2023-04-28 22:13 ` cvs-commit at gcc dot gnu.org
@ 2023-04-28 22:16 ` ppalka at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-04-28 22:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12.3+, thanks for the bug report.

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

end of thread, other threads:[~2023-04-28 22:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-24 22:04 [Bug c++/108219] New: requirement fails on a valid expression vanyacpp at gmail dot com
2022-12-24 23:33 ` [Bug c++/108219] [12/13 Regression] " pinskia at gcc dot gnu.org
2022-12-27 12:35 ` [Bug c++/108219] [12/13 Regression] requirement fails on a valid expression since r12-5253-g4df7f8c79835d569 marxin at gcc dot gnu.org
2023-01-09 13:42 ` rguenth at gcc dot gnu.org
2023-02-22 17:19 ` ppalka at gcc dot gnu.org
2023-03-01 19:09 ` cvs-commit at gcc dot gnu.org
2023-03-01 19:11 ` [Bug c++/108219] [12 " ppalka at gcc dot gnu.org
2023-03-03  9:35 ` vanyacpp at gmail dot com
2023-04-28 22:13 ` cvs-commit at gcc dot gnu.org
2023-04-28 22:16 ` 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).