public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98752] New: wrong "error: ‘this’ is not a constant expression" with consteval constructor
@ 2021-01-19 19:59 sbergman at redhat dot com
  2021-01-19 20:20 ` [Bug c++/98752] " mpolacek at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: sbergman at redhat dot com @ 2021-01-19 19:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98752
           Summary: wrong "error: ‘this’ is not a constant expression"
                    with consteval constructor
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

At least with gcc-c++-10.2.1-9.fc33.x86_64 and with a local GCC 11 trunk build:

> $ cat test.cc
> struct S1 { consteval S1(int) {} };
> struct S2 {
>   S1 x;
>   S2(): x(0) {}
> };

> $ g++ -std=c++20 -fsyntax-only test.cc
> test.cc: In constructor ‘S2::S2()’:
> test.cc:4:12: error: ‘this’ is not a constant expression
>     4 |   S2(): x(0) {}
>       |            ^

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

* [Bug c++/98752] wrong "error: ‘this’ is not a constant expression" with consteval constructor
  2021-01-19 19:59 [Bug c++/98752] New: wrong "error: ‘this’ is not a constant expression" with consteval constructor sbergman at redhat dot com
@ 2021-01-19 20:20 ` mpolacek at gcc dot gnu.org
  2021-01-19 20:31 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-19 20:20 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

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

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.  Not a regression.

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

* [Bug c++/98752] wrong "error: ‘this’ is not a constant expression" with consteval constructor
  2021-01-19 19:59 [Bug c++/98752] New: wrong "error: ‘this’ is not a constant expression" with consteval constructor sbergman at redhat dot com
  2021-01-19 20:20 ` [Bug c++/98752] " mpolacek at gcc dot gnu.org
@ 2021-01-19 20:31 ` jakub at gcc dot gnu.org
  2021-01-19 20:37 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-19 20:31 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
But if we can fix it, I'd think it would be worth an exception.

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

* [Bug c++/98752] wrong "error: ‘this’ is not a constant expression" with consteval constructor
  2021-01-19 19:59 [Bug c++/98752] New: wrong "error: ‘this’ is not a constant expression" with consteval constructor sbergman at redhat dot com
  2021-01-19 20:20 ` [Bug c++/98752] " mpolacek at gcc dot gnu.org
  2021-01-19 20:31 ` jakub at gcc dot gnu.org
@ 2021-01-19 20:37 ` mpolacek at gcc dot gnu.org
  2021-01-20  9:25 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-19 20:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #2)
> But if we can fix it, I'd think it would be worth an exception.

Given the fix would likely only affect C++20 code, I think that would be
reasonable.

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

* [Bug c++/98752] wrong "error: ‘this’ is not a constant expression" with consteval constructor
  2021-01-19 19:59 [Bug c++/98752] New: wrong "error: ‘this’ is not a constant expression" with consteval constructor sbergman at redhat dot com
                   ` (2 preceding siblings ...)
  2021-01-19 20:37 ` mpolacek at gcc dot gnu.org
@ 2021-01-20  9:25 ` jakub at gcc dot gnu.org
  2021-12-09  7:47 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-20  9:25 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Due to the consteval we call cxx_constant_value with
S1::S1 (&((struct S2 *) this)->x, NON_LVALUE_EXPR <0>)
and
((struct S2 *) this)->x
arguments.  Shall we turn it into construction on a dummy object instead
somewhere, or shall cxx_eval_* for arguments equal to ctx->object be more
permissive in certain cases?

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

* [Bug c++/98752] wrong "error: ‘this’ is not a constant expression" with consteval constructor
  2021-01-19 19:59 [Bug c++/98752] New: wrong "error: ‘this’ is not a constant expression" with consteval constructor sbergman at redhat dot com
                   ` (3 preceding siblings ...)
  2021-01-20  9:25 ` jakub at gcc dot gnu.org
@ 2021-12-09  7:47 ` pinskia at gcc dot gnu.org
  2023-12-06 19:46 ` sberg.fun at gmail dot com
  2024-02-16 16:39 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-09  7:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2021-01-19 00:00:00         |2021-12-8

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
struct S1 { consteval S1(int) {} };
struct S2 {
  S1 x;
  S2(): x(0) {}
};

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

* [Bug c++/98752] wrong "error: ‘this’ is not a constant expression" with consteval constructor
  2021-01-19 19:59 [Bug c++/98752] New: wrong "error: ‘this’ is not a constant expression" with consteval constructor sbergman at redhat dot com
                   ` (4 preceding siblings ...)
  2021-12-09  7:47 ` pinskia at gcc dot gnu.org
@ 2023-12-06 19:46 ` sberg.fun at gmail dot com
  2024-02-16 16:39 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: sberg.fun at gmail dot com @ 2023-12-06 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Stephan Bergmann <sberg.fun at gmail dot com> ---
While the original reproducer from comment 0 appears to be fixed in recent GCC
14 trunk, a slight modification still fails at least with recent GCC 14 trunk:

> $ cat test.cc
> struct S1 {
>   int a;
>   consteval S1(int n): a(n) {}
> };
> struct S2 {
>   S1 x;
>   S2(): x(0) {}
> };

> $ g++ -fsyntax-only -std=c++20 test.cc
> test.cc: In constructor ‘S2::S2()’:
> test.cc:7:11: error: call to consteval function ‘((S2*)this)->S2::x.S1::S1(0)’ is not a constant expression
>     7 |     S2(): x(0) {}
>       |           ^~~~
> test.cc:7:11:   in ‘constexpr’ expansion of ‘((S2*)this)->S2::x.S1::S1(0)’
> test.cc:3:26: error: modification of ‘*(S2*)this’ is not a constant expression
>     3 |     consteval S1(int n): a(n) {}
>       |                          ^~~~

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

* [Bug c++/98752] wrong "error: ‘this’ is not a constant expression" with consteval constructor
  2021-01-19 19:59 [Bug c++/98752] New: wrong "error: ‘this’ is not a constant expression" with consteval constructor sbergman at redhat dot com
                   ` (5 preceding siblings ...)
  2023-12-06 19:46 ` sberg.fun at gmail dot com
@ 2024-02-16 16:39 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-16 16:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Comment 5 test was fixed by r14-5979-g99d114c15523e0

commit 99d114c15523e0bfe7a89ef1947f82eb5ff0260b
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Nov 17 14:48:44 2023 -0500

    c++: P2280R4, Using unknown refs in constant expr [PR106650]

the comment 6 one still doesn't work.

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

end of thread, other threads:[~2024-02-16 16:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-19 19:59 [Bug c++/98752] New: wrong "error: ‘this’ is not a constant expression" with consteval constructor sbergman at redhat dot com
2021-01-19 20:20 ` [Bug c++/98752] " mpolacek at gcc dot gnu.org
2021-01-19 20:31 ` jakub at gcc dot gnu.org
2021-01-19 20:37 ` mpolacek at gcc dot gnu.org
2021-01-20  9:25 ` jakub at gcc dot gnu.org
2021-12-09  7:47 ` pinskia at gcc dot gnu.org
2023-12-06 19:46 ` sberg.fun at gmail dot com
2024-02-16 16:39 ` mpolacek 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).