public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand
@ 2022-12-24 15:52 StevenSun2021 at hotmail dot com
  2022-12-24 16:00 ` [Bug c++/108218] " StevenSun2021 at hotmail dot com
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: StevenSun2021 at hotmail dot com @ 2022-12-24 15:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108218
           Summary: [12 Regression] Constant arguments in the new
                    expression is not checked in unevaluated operand
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: StevenSun2021 at hotmail dot com
  Target Milestone: ---

```
int main() {
    decltype(new int[-1]) a; // compiles with g++-12! <- regression here
                             // does not compile with g++-11


    auto b = new int[-1];    // does not compile with g++-12
                             // does not compile with g++-11
}
```
https://godbolt.org/z/aMGMrbfrd


expected behavior:
if, after conversion to std::size_t, the first dimension is a core constant
expression and it is potentially evaluated, the program is ill-formed.
https://en.cppreference.com/w/cpp/language/new

gcc(<=11.3 (current version)) and clang(>=3) does this check.

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

* [Bug c++/108218] [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
@ 2022-12-24 16:00 ` StevenSun2021 at hotmail dot com
  2022-12-24 19:19 ` [Bug c++/108218] [12/13 " pinskia at gcc dot gnu.org
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: StevenSun2021 at hotmail dot com @ 2022-12-24 16:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Steven Sun <StevenSun2021 at hotmail dot com> ---
My concern is that, expressions within the require expressions are also
considered as "unevaluated operands".

Thus, the following concept is evaluated as true, but the program is ill-formed
and does not compile (since gcc 12)


https://godbolt.org/z/bcc398chG
```
template<class T>
concept C = requires
{
    new int[(int)sizeof(T) - 4];
};

template<typename T> requires C<T>
class CC {
    CC() {
        new int[(int)sizeof(T) - 4];
    }
};

template class CC<char>;

```



<source>: In instantiation of 'CC<T>::CC() [with T = char]':
<source>:16:16:   required from here
<source>:12:32: error: size '-3' of array is negative
   12 |         new int[(int)sizeof(T) - 4];
      |                 ~~~~~~~~~~~~~~~^~~

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
  2022-12-24 16:00 ` [Bug c++/108218] " StevenSun2021 at hotmail dot com
@ 2022-12-24 19:19 ` pinskia at gcc dot gnu.org
  2022-12-24 20:44 ` StevenSun2021 at hotmail dot com
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-24 19:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-12-24
      Known to work|                            |11.3.0
     Ever confirmed|0                           |1
            Summary|[12 Regression] Constant    |[12/13 Regression] Constant
                   |arguments in the new        |arguments in the new
                   |expression is not checked   |expression is not checked
                   |in unevaluated operand      |in unevaluated operand
      Known to fail|                            |12.1.0
   Target Milestone|---                         |12.3
           Keywords|                            |needs-bisection,
                   |                            |rejects-valid

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Here is a rejects valid code:
template<class T>
concept C = requires
{
    new int[(int)sizeof(T) - 4];
};

template<typename T>
class CC {
    CC()  requires C<T> {
        new int[(int)sizeof(T) - 4];
    }
    CC()   {
    }
};

template class CC<char>;

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
  2022-12-24 16:00 ` [Bug c++/108218] " StevenSun2021 at hotmail dot com
  2022-12-24 19:19 ` [Bug c++/108218] [12/13 " pinskia at gcc dot gnu.org
@ 2022-12-24 20:44 ` StevenSun2021 at hotmail dot com
  2022-12-24 20:46 ` pinskia at gcc dot gnu.org
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: StevenSun2021 at hotmail dot com @ 2022-12-24 20:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Steven Sun <StevenSun2021 at hotmail dot com> ---
Bisecting tells me:

2551cd4f9bc1afee444a56e03c1cee6899593da9 is bad
adcfd2c45c3523d74279b5fcac1d7c6c34dd1382 is good



I think commit ddd25bd1a7c8f456bc914e34b77d43f39a1062d4 might be the root
cause.

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (2 preceding siblings ...)
  2022-12-24 20:44 ` StevenSun2021 at hotmail dot com
@ 2022-12-24 20:46 ` pinskia at gcc dot gnu.org
  2022-12-24 20:49 ` StevenSun2021 at hotmail dot com
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-24 20:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Steven Sun from comment #3)
> Bisecting tells me:
> 
> 2551cd4f9bc1afee444a56e03c1cee6899593da9 is bad
> adcfd2c45c3523d74279b5fcac1d7c6c34dd1382 is good
> 
> 
> 
> I think commit ddd25bd1a7c8f456bc914e34b77d43f39a1062d4 might be the root
> cause.

r12-2230-gddd25bd1a7c8f4

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (3 preceding siblings ...)
  2022-12-24 20:46 ` pinskia at gcc dot gnu.org
@ 2022-12-24 20:49 ` StevenSun2021 at hotmail dot com
  2022-12-24 20:56 ` StevenSun2021 at hotmail dot com
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: StevenSun2021 at hotmail dot com @ 2022-12-24 20:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Steven Sun <StevenSun2021 at hotmail dot com> ---
h:4df7f8c79835d56928f51f9e674d326300936e8e

sorry, copied wrong hash code

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (4 preceding siblings ...)
  2022-12-24 20:49 ` StevenSun2021 at hotmail dot com
@ 2022-12-24 20:56 ` StevenSun2021 at hotmail dot com
  2022-12-24 22:53 ` StevenSun2021 at hotmail dot com
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: StevenSun2021 at hotmail dot com @ 2022-12-24 20:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Steven Sun <StevenSun2021 at hotmail dot com> ---
g:4df7f8c79835d56928f51f9e674d326300936e8e

c++: don't do constexpr folding in unevaluated context

The implicit constexpr patch revealed that we were doing constant evaluation
of arbitrary expressions in unevaluated contexts, leading to failure when we
tried to evaluate e.g. a call to declval.  This is wrong more generally;
only manifestly-constant-evaluated expressions should be evaluated within
an unevaluated operand.

Making this change revealed a case we were failing to mark as manifestly
constant-evaluated.

gcc/cp/ChangeLog:

* constexpr.c (maybe_constant_value): Don't evaluate
in an unevaluated operand unless manifestly const-evaluated.
(fold_non_dependent_expr_template): Likewise.
* decl.c (compute_array_index_type_loc): This context is
manifestly constant-evaluated.

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (5 preceding siblings ...)
  2022-12-24 20:56 ` StevenSun2021 at hotmail dot com
@ 2022-12-24 22:53 ` StevenSun2021 at hotmail dot com
  2022-12-27 12:24 ` [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569 marxin at gcc dot gnu.org
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: StevenSun2021 at hotmail dot com @ 2022-12-24 22:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Steven Sun <StevenSun2021 at hotmail dot com> ---
I got one simple idea as a workaround. I do not have the resources to do the
tests.

I agree anyone to take the following patch or the idea.


From 35b4186a0ed3671de603bed6df5fb1156f087581 Mon Sep 17 00:00:00 2001
From: Steven Sun <stevensun2021@hotmail.com>
Date: Sun, 25 Dec 2022 06:44:43 +0800
Subject: [PATCH] c++: escape unevaluated context in new-expression

---
 gcc/cp/init.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index b49a7ca9169..974ea95959e 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -3929,7 +3929,12 @@ build_new (location_t loc, vec<tree, va_gc> **placement,
tree type,
       /* Try to determine the constant value only for the purposes
         of the diagnostic below but continue to use the original
         value and handle const folding later.  */
+      /* Escape the possible unevaluated context. Constant folding does
+   not work in unevaluated context, but is required in nelts.  */
+      int old_cp_unevaluated_operand = cp_unevaluated_operand;
+      cp_unevaluated_operand = false;
       const_tree cst_nelts = fold_non_dependent_expr (nelts, complain);
+      cp_unevaluated_operand = old_cp_unevaluated_operand;

       /* The expression in a noptr-new-declarator is erroneous if it's of
         non-class type and its value before converting to std::size_t is
-- 
2.34.1

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (6 preceding siblings ...)
  2022-12-24 22:53 ` StevenSun2021 at hotmail dot com
@ 2022-12-27 12:24 ` marxin at gcc dot gnu.org
  2023-01-09 13:42 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-27 12:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[12/13 Regression] Constant |[12/13 Regression] Constant
                   |arguments in the new        |arguments in the new
                   |expression is not checked   |expression is not checked
                   |in unevaluated operand      |in unevaluated operand
                   |                            |since
                   |                            |r12-5253-g4df7f8c79835d569
           Keywords|needs-bisection             |
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org

--- Comment #8 from Martin Liška <marxin at gcc dot gnu.org> ---
I can confirm it started with r12-5253-g4df7f8c79835d569.

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (7 preceding siblings ...)
  2022-12-27 12:24 ` [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569 marxin at gcc dot gnu.org
@ 2023-01-09 13:42 ` rguenth at gcc dot gnu.org
  2023-01-10 15:16 ` ppalka at gcc dot gnu.org
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 18+ 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=108218

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

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

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (8 preceding siblings ...)
  2023-01-09 13:42 ` rguenth at gcc dot gnu.org
@ 2023-01-10 15:16 ` ppalka at gcc dot gnu.org
  2023-01-10 18:52 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-01-10 15:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=108219

--- Comment #9 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Steven Sun from comment #7)
> I got one simple idea as a workaround. I do not have the resources to do the
> tests.

FWIW that seems like the right idea, but it regresses
gcc/testsuite/g++.dg/DRs/dr2392.C:

$ cat gcc/testsuite/g++.dg/DRs/dr2392.C
// DR 2392
// { dg-do compile { target c++11 } }

template <class T = void>
constexpr int
foo ()
{
  T t;
  return 1;
}

using V = decltype (new int[foo ()]);

$ gcc gcc/testsuite/g++.dg/DRs/dr2392.C
gcc/testsuite/g++.dg/DRs/dr2392.C: In instantiation of ‘constexpr int foo()
[with T = void]’:
gcc/testsuite/g++.dg/DRs/dr2392.C:12:33:   required from here
gcc/testsuite/g++.dg/DRs/dr2392.C:8:5: error: variable or field ‘t’ declared
void
    8 |   T t;
      |     ^

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (9 preceding siblings ...)
  2023-01-10 15:16 ` ppalka at gcc dot gnu.org
@ 2023-01-10 18:52 ` pinskia at gcc dot gnu.org
  2023-01-21 17:22 ` StevenSun2021 at hotmail dot com
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-10 18:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2392

"potentially-evaluated".

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (10 preceding siblings ...)
  2023-01-10 18:52 ` pinskia at gcc dot gnu.org
@ 2023-01-21 17:22 ` StevenSun2021 at hotmail dot com
  2023-01-25  2:59 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: StevenSun2021 at hotmail dot com @ 2023-01-21 17:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Steven Sun <StevenSun2021 at hotmail dot com> ---
(In reply to Andrew Pinski from comment #10)
> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2392
> 
> "potentially-evaluated".

Oh, I realized that,

According to the DR 2392 accepted as a DR at the November, 2022 meeting:

https://cplusplus.github.io/CWG/issues/2392.html

We should not evaluate that expression in the first dimension of `new` anymore.
So this is not a bug.

This also applys for expressions appearing in requirement-seq of
requires-expressions.

So surprising! (Correct me if I am wrong)

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (11 preceding siblings ...)
  2023-01-21 17:22 ` StevenSun2021 at hotmail dot com
@ 2023-01-25  2:59 ` jason at gcc dot gnu.org
  2023-01-25  3:19 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: jason at gcc dot gnu.org @ 2023-01-25  2:59 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> ---
So, not a bug.

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (12 preceding siblings ...)
  2023-01-25  2:59 ` jason at gcc dot gnu.org
@ 2023-01-25  3:19 ` jason at gcc dot gnu.org
  2023-03-01 19:09 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: jason at gcc dot gnu.org @ 2023-01-25  3:19 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |SUSPENDED
         Resolution|INVALID                     |---
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org

--- Comment #13 from Jason Merrill <jason at gcc dot gnu.org> ---
Actually, I'm going to suspend this and ask about reconsidering the resolution.

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

* [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (13 preceding siblings ...)
  2023-01-25  3:19 ` jason at gcc dot gnu.org
@ 2023-03-01 19:09 ` cvs-commit at gcc dot gnu.org
  2023-04-28 22:13 ` [Bug c++/108218] [12/13/14 " cvs-commit at gcc dot gnu.org
  2023-05-08 12:26 ` rguenth at gcc dot gnu.org
  16 siblings, 0 replies; 18+ 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=108218

--- Comment #14 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] 18+ messages in thread

* [Bug c++/108218] [12/13/14 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (14 preceding siblings ...)
  2023-03-01 19:09 ` cvs-commit at gcc dot gnu.org
@ 2023-04-28 22:13 ` cvs-commit at gcc dot gnu.org
  2023-05-08 12:26 ` rguenth at gcc dot gnu.org
  16 siblings, 0 replies; 18+ 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=108218

--- Comment #15 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] 18+ messages in thread

* [Bug c++/108218] [12/13/14 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569
  2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
                   ` (15 preceding siblings ...)
  2023-04-28 22:13 ` [Bug c++/108218] [12/13/14 " cvs-commit at gcc dot gnu.org
@ 2023-05-08 12:26 ` rguenth at gcc dot gnu.org
  16 siblings, 0 replies; 18+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #16 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.

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

end of thread, other threads:[~2023-05-08 12:26 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-24 15:52 [Bug c++/108218] New: [12 Regression] Constant arguments in the new expression is not checked in unevaluated operand StevenSun2021 at hotmail dot com
2022-12-24 16:00 ` [Bug c++/108218] " StevenSun2021 at hotmail dot com
2022-12-24 19:19 ` [Bug c++/108218] [12/13 " pinskia at gcc dot gnu.org
2022-12-24 20:44 ` StevenSun2021 at hotmail dot com
2022-12-24 20:46 ` pinskia at gcc dot gnu.org
2022-12-24 20:49 ` StevenSun2021 at hotmail dot com
2022-12-24 20:56 ` StevenSun2021 at hotmail dot com
2022-12-24 22:53 ` StevenSun2021 at hotmail dot com
2022-12-27 12:24 ` [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand since r12-5253-g4df7f8c79835d569 marxin at gcc dot gnu.org
2023-01-09 13:42 ` rguenth at gcc dot gnu.org
2023-01-10 15:16 ` ppalka at gcc dot gnu.org
2023-01-10 18:52 ` pinskia at gcc dot gnu.org
2023-01-21 17:22 ` StevenSun2021 at hotmail dot com
2023-01-25  2:59 ` jason at gcc dot gnu.org
2023-01-25  3:19 ` jason at gcc dot gnu.org
2023-03-01 19:09 ` cvs-commit at gcc dot gnu.org
2023-04-28 22:13 ` [Bug c++/108218] [12/13/14 " cvs-commit at gcc dot gnu.org
2023-05-08 12:26 ` rguenth 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).