public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114219] New: [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes
@ 2024-03-03  8:05 janschultke at googlemail dot com
  2024-03-03  8:10 ` [Bug c++/114219] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: janschultke at googlemail dot com @ 2024-03-03  8:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114219
           Summary: [expr.const] lvalue-to-rvalue conversion is not
                    diagnosed to disqualify constant expressions for empty
                    classes
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janschultke at googlemail dot com
  Target Milestone: ---

https://godbolt.org/z/jhcP8WPn8

Code to reproduce
=================

struct S {};

constexpr int f(S s) {
    constexpr S _ = s;
    return 0;
}

S s;
constexpr int _ = f(s);



Issue description
=================

This code compiles, but should produce errors for both constexpr
initializations.

According to [expr.const] p5.9, the initializers of _ cannot be constant
expression because they contain lvalue-to-rvalue conversion of s, whose
lifetime did not begin within the evaluation of the constant expression, and
which is not usable in constant expressions.

It shouldn't matter whether S is an empty class or has members; the
lvalue-to-rvalue conversion in itself disqualifies expressions from being
constant expressions.

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

* [Bug c++/114219] [11/12/13/14 Regression] [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes
  2024-03-03  8:05 [Bug c++/114219] New: [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes janschultke at googlemail dot com
@ 2024-03-03  8:10 ` pinskia at gcc dot gnu.org
  2024-03-03  8:15 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-03  8:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[expr.const]                |[11/12/13/14 Regression]
                   |lvalue-to-rvalue conversion |[expr.const]
                   |is not diagnosed to         |lvalue-to-rvalue conversion
                   |disqualify constant         |is not diagnosed to
                   |expressions for empty       |disqualify constant
                   |classes                     |expressions for empty
                   |                            |classes
      Known to work|                            |5.1.0, 6.1.0
   Target Milestone|---                         |11.5
      Known to fail|                            |7.1.0

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

* [Bug c++/114219] [11/12/13/14 Regression] [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes
  2024-03-03  8:05 [Bug c++/114219] New: [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes janschultke at googlemail dot com
  2024-03-03  8:10 ` [Bug c++/114219] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2024-03-03  8:15 ` pinskia at gcc dot gnu.org
  2024-03-03  8:18 ` janschultke at googlemail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-03  8:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, clang also accepts this ...

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

* [Bug c++/114219] [11/12/13/14 Regression] [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes
  2024-03-03  8:05 [Bug c++/114219] New: [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes janschultke at googlemail dot com
  2024-03-03  8:10 ` [Bug c++/114219] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
  2024-03-03  8:15 ` pinskia at gcc dot gnu.org
@ 2024-03-03  8:18 ` janschultke at googlemail dot com
  2024-03-03  8:21 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: janschultke at googlemail dot com @ 2024-03-03  8:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jan Schultke <janschultke at googlemail dot com> ---
Corresponding LLVM bug: https://github.com/llvm/llvm-project/issues/83712

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

* [Bug c++/114219] [11/12/13/14 Regression] [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes
  2024-03-03  8:05 [Bug c++/114219] New: [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes janschultke at googlemail dot com
                   ` (2 preceding siblings ...)
  2024-03-03  8:18 ` janschultke at googlemail dot com
@ 2024-03-03  8:21 ` pinskia at gcc dot gnu.org
  2024-03-03  8:33 ` janschultke at googlemail dot com
  2024-03-03 18:08 ` janschultke at googlemail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-03  8:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=91953

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539673.html


hmm reading https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91953#c3 implies there
is no lvalue-to-rvalue conversion happening ...

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

* [Bug c++/114219] [11/12/13/14 Regression] [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes
  2024-03-03  8:05 [Bug c++/114219] New: [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes janschultke at googlemail dot com
                   ` (3 preceding siblings ...)
  2024-03-03  8:21 ` pinskia at gcc dot gnu.org
@ 2024-03-03  8:33 ` janschultke at googlemail dot com
  2024-03-03 18:08 ` janschultke at googlemail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: janschultke at googlemail dot com @ 2024-03-03  8:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jan Schultke <janschultke at googlemail dot com> ---
I don't see how lvalue-to-rvalue conversion would be bypassed here.

https://eel.is/c++draft/conv.lval#:conversion,lvalue-to-rvalue has no special
provision for empty classes.

https://eel.is/c++draft/dcl.init.general#16.9 would necessitate
lvalue-to-rvalue conversion because the initializer has to be converted to a
prvalue. I couldn't find any special rule for empty classes.

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

* [Bug c++/114219] [11/12/13/14 Regression] [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes
  2024-03-03  8:05 [Bug c++/114219] New: [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes janschultke at googlemail dot com
                   ` (4 preceding siblings ...)
  2024-03-03  8:33 ` janschultke at googlemail dot com
@ 2024-03-03 18:08 ` janschultke at googlemail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: janschultke at googlemail dot com @ 2024-03-03 18:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jan Schultke <janschultke at googlemail dot com> changed:

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

--- Comment #5 from Jan Schultke <janschultke at googlemail dot com> ---
Looks like the existing comments were right.

Lvalue-to-rvalue conversion very rarely takes place for class types, and if it
does, that may be a wording bug.

Instead of lvalue-to-rvalue conversion, this case calls the implicitly-defined
copy constructor, which can be used in constant expressions.

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

end of thread, other threads:[~2024-03-03 18:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-03  8:05 [Bug c++/114219] New: [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes janschultke at googlemail dot com
2024-03-03  8:10 ` [Bug c++/114219] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-03-03  8:15 ` pinskia at gcc dot gnu.org
2024-03-03  8:18 ` janschultke at googlemail dot com
2024-03-03  8:21 ` pinskia at gcc dot gnu.org
2024-03-03  8:33 ` janschultke at googlemail dot com
2024-03-03 18:08 ` janschultke at googlemail dot com

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