public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114709] New: Incorrect handling of inactive union member access via pointer to member in constant evaluated context
@ 2024-04-13 1:59 420 at zerberste dot es
2024-04-13 8:51 ` [Bug c++/114709] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: 420 at zerberste dot es @ 2024-04-13 1:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114709
Bug ID: 114709
Summary: Incorrect handling of inactive union member access via
pointer to member in constant evaluated context
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: 420 at zerberste dot es
Target Milestone: ---
According to https://standards.pydong.org/c++/class.union#general-note-1 an
inactive union member may be used to inspect the initial sequence common with
the active union member, given both are struct types. Furthermore
https://standards.pydong.org/c++/class.mem#general-26 tells us the behavior of
reading a non-static member m of such a common initial sequence is _as if_ the
corresponding member were nominated. Since it is not expression-equivalent, we
are still accessing the wrong member as far as the abstract machine is
concerned. Hence https://standards.pydong.org/c++/expr.const#5.10 still
applies.
GCC implements this correctly for the simple case. To reuse the example from
[class.mem]/26 consider this code fragment:
```cpp
struct T1 { int a, b; };
struct T2 { int c; double d; };
union U { T1 t1; T2 t2; };
consteval int f() {
U u = { { 1, 2 } }; // active member is t1
return u.t2.c; // access through t2
}
static constexpr auto foo = f();
```
https://godbolt.org/z/x14n47T45
GCC correctly errors with the diagnostic
> accessing 'U::t2' member instead of initialized 'U::t1' member in constant expression
However, consider the following code fragment:
```cpp
struct T1 { int a, b; };
struct T2 { int c; double d; };
union U { T1 t1; T2 t2; };
consteval int f() {
U u = { { 1, 2 } }; // active member is t1
return u.t2.*&T2::c; // access through t2
}
static constexpr auto foo = f();
```
https://godbolt.org/z/dK95jEPjq
GCC 12 up until trunk accept this code. GCC 11 and Clang don't.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/114709] Incorrect handling of inactive union member access via pointer to member in constant evaluated context
2024-04-13 1:59 [Bug c++/114709] New: Incorrect handling of inactive union member access via pointer to member in constant evaluated context 420 at zerberste dot es
@ 2024-04-13 8:51 ` pinskia at gcc dot gnu.org
2024-04-13 8:52 ` [Bug c++/114709] [12/13/14 Regression] " pinskia at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-13 8:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114709
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
Last reconfirmed| |2024-04-13
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/114709] [12/13/14 Regression] Incorrect handling of inactive union member access via pointer to member in constant evaluated context
2024-04-13 1:59 [Bug c++/114709] New: Incorrect handling of inactive union member access via pointer to member in constant evaluated context 420 at zerberste dot es
2024-04-13 8:51 ` [Bug c++/114709] " pinskia at gcc dot gnu.org
@ 2024-04-13 8:52 ` pinskia at gcc dot gnu.org
2024-04-17 13:33 ` law at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-13 8:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114709
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.4
Known to work| |11.4.0
Known to fail| |12.1.0
Summary|Incorrect handling of |[12/13/14 Regression]
|inactive union member |Incorrect handling of
|access via pointer to |inactive union member
|member in constant |access via pointer to
|evaluated context |member in constant
| |evaluated context
Keywords| |needs-bisection
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/114709] [12/13/14 Regression] Incorrect handling of inactive union member access via pointer to member in constant evaluated context
2024-04-13 1:59 [Bug c++/114709] New: Incorrect handling of inactive union member access via pointer to member in constant evaluated context 420 at zerberste dot es
2024-04-13 8:51 ` [Bug c++/114709] " pinskia at gcc dot gnu.org
2024-04-13 8:52 ` [Bug c++/114709] [12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2024-04-17 13:33 ` law at gcc dot gnu.org
2024-04-19 7:19 ` [Bug c++/114709] [12/13/14 Regression] Incorrect handling of inactive union member access via pointer to member in constant evaluated context since r12-6425 jakub at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: law at gcc dot gnu.org @ 2024-04-17 13:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114709
Jeffrey A. Law <law at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
CC| |law at gcc dot gnu.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/114709] [12/13/14 Regression] Incorrect handling of inactive union member access via pointer to member in constant evaluated context since r12-6425
2024-04-13 1:59 [Bug c++/114709] New: Incorrect handling of inactive union member access via pointer to member in constant evaluated context 420 at zerberste dot es
` (2 preceding siblings ...)
2024-04-17 13:33 ` law at gcc dot gnu.org
@ 2024-04-19 7:19 ` jakub at gcc dot gnu.org
2024-04-19 17:51 ` ppalka at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-19 7:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114709
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[12/13/14 Regression] |[12/13/14 Regression]
|Incorrect handling of |Incorrect handling of
|inactive union member |inactive union member
|access via pointer to |access via pointer to
|member in constant |member in constant
|evaluated context |evaluated context since
| |r12-6425
CC| |jakub at gcc dot gnu.org,
| |ppalka at gcc dot gnu.org
Keywords|needs-bisection |
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is accepted since r12-6425-gab36b554bd90e8db279d13b133369118814f13fb
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/114709] [12/13/14 Regression] Incorrect handling of inactive union member access via pointer to member in constant evaluated context since r12-6425
2024-04-13 1:59 [Bug c++/114709] New: Incorrect handling of inactive union member access via pointer to member in constant evaluated context 420 at zerberste dot es
` (3 preceding siblings ...)
2024-04-19 7:19 ` [Bug c++/114709] [12/13/14 Regression] Incorrect handling of inactive union member access via pointer to member in constant evaluated context since r12-6425 jakub at gcc dot gnu.org
@ 2024-04-19 17:51 ` ppalka at gcc dot gnu.org
2024-04-24 21:50 ` cvs-commit at gcc dot gnu.org
2024-04-24 21:52 ` [Bug c++/114709] [12/13 " ppalka at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-04-19 17:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114709
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/114709] [12/13/14 Regression] Incorrect handling of inactive union member access via pointer to member in constant evaluated context since r12-6425
2024-04-13 1:59 [Bug c++/114709] New: Incorrect handling of inactive union member access via pointer to member in constant evaluated context 420 at zerberste dot es
` (4 preceding siblings ...)
2024-04-19 17:51 ` ppalka at gcc dot gnu.org
@ 2024-04-24 21:50 ` cvs-commit at gcc dot gnu.org
2024-04-24 21:52 ` [Bug c++/114709] [12/13 " ppalka at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-24 21:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114709
--- Comment #3 from GCC 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:0844170e9ef60a8b2f6fba6786672f30ce1c2749
commit r14-10110-g0844170e9ef60a8b2f6fba6786672f30ce1c2749
Author: Patrick Palka <ppalka@redhat.com>
Date: Wed Apr 24 17:49:56 2024 -0400
c++: constexpr union member access folding [PR114709]
The object/offset canonicalization performed in cxx_fold_indirect_ref
is undesirable for union member accesses because it loses information
about the member being accessed which we may later need to diagnose an
inactive-member access. So this patch restricts the canonicalization
accordingly.
PR c++/114709
gcc/cp/ChangeLog:
* constexpr.cc (cxx_fold_indirect_ref): Restrict object/offset
canonicalization to RECORD_TYPE member accesses.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-union8.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/114709] [12/13 Regression] Incorrect handling of inactive union member access via pointer to member in constant evaluated context since r12-6425
2024-04-13 1:59 [Bug c++/114709] New: Incorrect handling of inactive union member access via pointer to member in constant evaluated context 420 at zerberste dot es
` (5 preceding siblings ...)
2024-04-24 21:50 ` cvs-commit at gcc dot gnu.org
@ 2024-04-24 21:52 ` ppalka at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-04-24 21:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114709
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[12/13/14 Regression] |[12/13 Regression]
|Incorrect handling of |Incorrect handling of
|inactive union member |inactive union member
|access via pointer to |access via pointer to
|member in constant |member in constant
|evaluated context since |evaluated context since
|r12-6425 |r12-6425
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 14 so far.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-04-24 21:52 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-13 1:59 [Bug c++/114709] New: Incorrect handling of inactive union member access via pointer to member in constant evaluated context 420 at zerberste dot es
2024-04-13 8:51 ` [Bug c++/114709] " pinskia at gcc dot gnu.org
2024-04-13 8:52 ` [Bug c++/114709] [12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-04-17 13:33 ` law at gcc dot gnu.org
2024-04-19 7:19 ` [Bug c++/114709] [12/13/14 Regression] Incorrect handling of inactive union member access via pointer to member in constant evaluated context since r12-6425 jakub at gcc dot gnu.org
2024-04-19 17:51 ` ppalka at gcc dot gnu.org
2024-04-24 21:50 ` cvs-commit at gcc dot gnu.org
2024-04-24 21:52 ` [Bug c++/114709] [12/13 " 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).