public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102163] New: std::variant rejects valid constant expression
@ 2021-09-01 16:57 hewillk at gmail dot com
  2021-09-01 20:55 ` [Bug c++/102163] [10/11/12 Regression] " ppalka at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2021-09-01 16:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102163
           Summary: std::variant rejects valid constant expression
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

#include <variant>

struct O {
  O() = default;
  O(O&&) = default;
  O(const O&) = default;
  O& operator=(const O&) = default;
  O& operator=(O&&) = default;
  ~O() = default;

  constexpr O(int x) {}
};

constexpr std::variant<float, O> v{42};

https://godbolt.org/z/PdEx4z7rf

GCC-trunk rejected it under -std=c++20, it seems to be a language feature bug.

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

* [Bug c++/102163] [10/11/12 Regression] std::variant rejects valid constant expression
  2021-09-01 16:57 [Bug c++/102163] New: std::variant rejects valid constant expression hewillk at gmail dot com
@ 2021-09-01 20:55 ` ppalka at gcc dot gnu.org
  2021-09-01 21:08 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-09-01 20:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.4
   Last reconfirmed|                            |2021-09-01
                 CC|                            |ppalka at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to work|                            |9.4.0
             Status|UNCONFIRMED                 |ASSIGNED
      Known to fail|                            |10.3.0, 11.2.0, 12.0
            Summary|std::variant rejects valid  |[10/11/12 Regression]
                   |constant expression         |std::variant rejects valid
                   |                            |constant expression

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Reduced rejects-valid testcase:

struct O {
  constexpr O(int) {}
};

union _Variadic_union
{
  constexpr _Variadic_union() : _M_rest(42) { }
  O _M_rest;
};

constexpr _Variadic_union w;

Started with r10-7313.

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

* [Bug c++/102163] [10/11/12 Regression] std::variant rejects valid constant expression
  2021-09-01 16:57 [Bug c++/102163] New: std::variant rejects valid constant expression hewillk at gmail dot com
  2021-09-01 20:55 ` [Bug c++/102163] [10/11/12 Regression] " ppalka at gcc dot gnu.org
@ 2021-09-01 21:08 ` pinskia at gcc dot gnu.org
  2021-09-01 21:09 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-01 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
PR 97665 is related but it does not have an intializer for _M_rest.

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

* [Bug c++/102163] [10/11/12 Regression] std::variant rejects valid constant expression
  2021-09-01 16:57 [Bug c++/102163] New: std::variant rejects valid constant expression hewillk at gmail dot com
  2021-09-01 20:55 ` [Bug c++/102163] [10/11/12 Regression] " ppalka at gcc dot gnu.org
  2021-09-01 21:08 ` pinskia at gcc dot gnu.org
@ 2021-09-01 21:09 ` pinskia at gcc dot gnu.org
  2021-09-14 15:23 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-01 21:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note this works:

struct O {
  constexpr O() {}
};

union _Variadic_union
{
  constexpr _Variadic_union() : _M_rest() { }
  O _M_rest;
};

constexpr _Variadic_union w;
----- CUT ---
But this fails:
struct O {
  constexpr O() {}
};

union _Variadic_union
{
  constexpr _Variadic_union() : _M_rest{} { }
  O _M_rest;
};

constexpr _Variadic_union w;

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

* [Bug c++/102163] [10/11/12 Regression] std::variant rejects valid constant expression
  2021-09-01 16:57 [Bug c++/102163] New: std::variant rejects valid constant expression hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2021-09-01 21:09 ` pinskia at gcc dot gnu.org
@ 2021-09-14 15:23 ` cvs-commit at gcc dot gnu.org
  2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-14 15:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:de07cff96abd43f6f65dcf333958899c2ec42598

commit r12-3527-gde07cff96abd43f6f65dcf333958899c2ec42598
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Sep 14 11:22:12 2021 -0400

    c++: empty union member activation during constexpr [PR102163]

    Here, the union's constructor is defined to activate its empty data
    member _M_rest, but during constexpr evaluation of this constructor the
    subobject constructor call O::O(&_M_rest, 42) doesn't produce a side
    effect that actually activates the member, so the union still appears
    uninitialized after its constructor has run.  This patch fixes this by
    using a dummy MODIFY_EXPR in this situation, whose evaluation ensures
    the member gets activated.

            PR c++/102163

    gcc/cp/ChangeLog:

            * constexpr.c (cxx_eval_call_expression): After evaluating a
            subobject constructor call for an empty union member, produce a
            side effect that makes sure the member gets activated.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-empty17.C: New test.

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

* [Bug c++/102163] [10/11/12 Regression] std::variant rejects valid constant expression
  2021-09-01 16:57 [Bug c++/102163] New: std::variant rejects valid constant expression hewillk at gmail dot com
                   ` (3 preceding siblings ...)
  2021-09-14 15:23 ` cvs-commit at gcc dot gnu.org
@ 2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
  2021-10-06 14:17 ` [Bug c++/102163] [10 " ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-06 14:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 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:59c6831682dfa8bec2b5a62bdc85739924970808

commit r11-9080-g59c6831682dfa8bec2b5a62bdc85739924970808
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Sep 14 11:22:12 2021 -0400

    c++: empty union member activation during constexpr [PR102163]

    Here, the union's constructor is defined to activate its empty data
    member _M_rest, but during constexpr evaluation of this constructor the
    subobject constructor call O::O(&_M_rest, 42) doesn't produce a side
    effect that actually activates the member, so the union still appears
    uninitialized after its constructor has run.  This patch fixes this by
    using a dummy MODIFY_EXPR in this situation, whose evaluation ensures
    the member gets activated.

            PR c++/102163

    gcc/cp/ChangeLog:

            * constexpr.c (cxx_eval_call_expression): After evaluating a
            subobject constructor call for an empty union member, produce a
            side effect that makes sure the member gets activated.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-empty17.C: New test.

    (cherry picked from commit de07cff96abd43f6f65dcf333958899c2ec42598)

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

* [Bug c++/102163] [10 Regression] std::variant rejects valid constant expression
  2021-09-01 16:57 [Bug c++/102163] New: std::variant rejects valid constant expression hewillk at gmail dot com
                   ` (4 preceding siblings ...)
  2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
@ 2021-10-06 14:17 ` ppalka at gcc dot gnu.org
  2022-06-28 10:46 ` jakub at gcc dot gnu.org
  2023-07-07  9:46 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-10-06 14:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11/12 Regression]       |[10 Regression]
                   |std::variant rejects valid  |std::variant rejects valid
                   |constant expression         |constant expression

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 11.3 and 12 so far.

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

* [Bug c++/102163] [10 Regression] std::variant rejects valid constant expression
  2021-09-01 16:57 [Bug c++/102163] New: std::variant rejects valid constant expression hewillk at gmail dot com
                   ` (5 preceding siblings ...)
  2021-10-06 14:17 ` [Bug c++/102163] [10 " ppalka at gcc dot gnu.org
@ 2022-06-28 10:46 ` jakub at gcc dot gnu.org
  2023-07-07  9:46 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

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

* [Bug c++/102163] [10 Regression] std::variant rejects valid constant expression
  2021-09-01 16:57 [Bug c++/102163] New: std::variant rejects valid constant expression hewillk at gmail dot com
                   ` (6 preceding siblings ...)
  2022-06-28 10:46 ` jakub at gcc dot gnu.org
@ 2023-07-07  9:46 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07  9:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to work|                            |11.3.0, 12.1.0
   Target Milestone|10.5                        |11.3
      Known to fail|12.0                        |10.5.0
         Resolution|---                         |FIXED

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
fixed

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

end of thread, other threads:[~2023-07-07  9:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01 16:57 [Bug c++/102163] New: std::variant rejects valid constant expression hewillk at gmail dot com
2021-09-01 20:55 ` [Bug c++/102163] [10/11/12 Regression] " ppalka at gcc dot gnu.org
2021-09-01 21:08 ` pinskia at gcc dot gnu.org
2021-09-01 21:09 ` pinskia at gcc dot gnu.org
2021-09-14 15:23 ` cvs-commit at gcc dot gnu.org
2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
2021-10-06 14:17 ` [Bug c++/102163] [10 " ppalka at gcc dot gnu.org
2022-06-28 10:46 ` jakub at gcc dot gnu.org
2023-07-07  9:46 ` 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).