public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110245] New: constant evaluation fails with uninitialized union and default constructor
@ 2023-06-14 3:47 danakj at orodu dot net
2023-06-14 3:52 ` [Bug c++/110245] " danakj at orodu dot net
2023-06-14 4:04 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: danakj at orodu dot net @ 2023-06-14 3:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110245
Bug ID: 110245
Summary: constant evaluation fails with uninitialized union and
default constructor
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: danakj at orodu dot net
Target Milestone: ---
```
struct Store {
constexpr Store() {}
union {
int i;
};
bool b = false;
};
struct C {
constexpr C() = default;
Store s;
};
int main() {
constexpr auto c = C(); //
}
```
This should compile but does not, GCC complains that it refers to an
incompletely initialized variable. Union members are not required to be active.
https://godbolt.org/z/G9vcosTG1
Reproduced on GCC trunk and GCC 11.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/110245] constant evaluation fails with uninitialized union and default constructor
2023-06-14 3:47 [Bug c++/110245] New: constant evaluation fails with uninitialized union and default constructor danakj at orodu dot net
@ 2023-06-14 3:52 ` danakj at orodu dot net
2023-06-14 4:04 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: danakj at orodu dot net @ 2023-06-14 3:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110245
--- Comment #1 from danakj at orodu dot net ---
Note that GCC has no problem with doing this constexpr construction if the
object is not stored as an lvalue.
```
struct Store {
constexpr Store() {}
union {
int i;
};
bool b = false;
};
struct C {
constexpr C() = default;
Store s;
};
int main() {
constexpr auto c = C(); // Fails.
constexpr auto b = C().s.b; // OK
}
```
https://godbolt.org/z/31MTenKoo
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/110245] constant evaluation fails with uninitialized union and default constructor
2023-06-14 3:47 [Bug c++/110245] New: constant evaluation fails with uninitialized union and default constructor danakj at orodu dot net
2023-06-14 3:52 ` [Bug c++/110245] " danakj at orodu dot net
@ 2023-06-14 4:04 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-14 4:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110245
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So if I read: https://cplusplus.github.io/CWG/issues/2558.html there is still
an open question about "Union types shall be initialized such that they have an
active member in the result of a constant expression" but I am not 100% sure
here.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-14 4:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 3:47 [Bug c++/110245] New: constant evaluation fails with uninitialized union and default constructor danakj at orodu dot net
2023-06-14 3:52 ` [Bug c++/110245] " danakj at orodu dot net
2023-06-14 4:04 ` pinskia 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).