public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/110828] New: union constexpr dtor not constexpr when used in member array @ 2023-07-27 10:06 gccbugbjorn at fahller dot se 2023-07-27 14:22 ` [Bug c++/110828] " ppalka at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: gccbugbjorn at fahller dot se @ 2023-07-27 10:06 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110828 Bug ID: 110828 Summary: union constexpr dtor not constexpr when used in member array Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gccbugbjorn at fahller dot se Target Milestone: --- The following code does not compile with g++ 13.1 or g++ trunk 82c2a34b2f2c1a06eff672eba2e447b53f35d7b0 union type { constexpr type(){} constexpr ~type() {} int t; }; struct S { constexpr S() = default; constexpr bool f() const { return true;} private: type v[1]; }; static_assert(S{}.f()); The error message is: source.cpp:16:20: error: non-constant condition for static assertion 16 | static_assert(S{}.f()); | ~~~~~^~ source.cpp:16:23: in 'constexpr' expansion of '(&<anonymous>)->S::~S()' source.cpp:7:8: error: '(((type*)(&<anonymous>.S::v)) != 0)' is not a constant expression 7 | struct S | ^ Two simple changes can each make it compile. 1. Comment out the constexpr destructor for 'type' 2. Remove [1] from the declaration of member variable S::v such that it is not an array. Link to compiler explorer: https://godbolt.org/z/q3KcKrPh1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/110828] union constexpr dtor not constexpr when used in member array 2023-07-27 10:06 [Bug c++/110828] New: union constexpr dtor not constexpr when used in member array gccbugbjorn at fahller dot se @ 2023-07-27 14:22 ` ppalka at gcc dot gnu.org 2023-07-27 16:25 ` gccbugbjorn at fahller dot se 2023-07-27 17:54 ` pinskia at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: ppalka at gcc dot gnu.org @ 2023-07-27 14:22 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110828 Patrick Palka <ppalka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ppalka at gcc dot gnu.org --- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> --- Does it work if you move the static_assert into a function scope? If so then this is probably a dup of PR85944. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/110828] union constexpr dtor not constexpr when used in member array 2023-07-27 10:06 [Bug c++/110828] New: union constexpr dtor not constexpr when used in member array gccbugbjorn at fahller dot se 2023-07-27 14:22 ` [Bug c++/110828] " ppalka at gcc dot gnu.org @ 2023-07-27 16:25 ` gccbugbjorn at fahller dot se 2023-07-27 17:54 ` pinskia at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: gccbugbjorn at fahller dot se @ 2023-07-27 16:25 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110828 --- Comment #2 from Björn Fahller <gccbugbjorn at fahller dot se> --- If I write it in the same way in a function, it compiles. consteval auto f() { return S{}.f(); } constexpr auto b = f(); However, if I break it into a constexpr object S s; and return s.f(), it does not compile, this time because the construction of 's' fails because it refers to an unititialized variable, regardless of whether the member is an array or not. union type { constexpr type(){} constexpr ~type() {} int t; }; struct S { constexpr S() {} constexpr bool f() const { return true;} type v{}; }; consteval auto f() { constexpr S s; return s.f(); } constexpr auto b = f(); https://godbolt.org/z/68zY6ecxs ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/110828] union constexpr dtor not constexpr when used in member array 2023-07-27 10:06 [Bug c++/110828] New: union constexpr dtor not constexpr when used in member array gccbugbjorn at fahller dot se 2023-07-27 14:22 ` [Bug c++/110828] " ppalka at gcc dot gnu.org 2023-07-27 16:25 ` gccbugbjorn at fahller dot se @ 2023-07-27 17:54 ` pinskia at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-07-27 17:54 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110828 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |DUPLICATE Status|UNCONFIRMED |RESOLVED --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Patrick Palka from comment #1) > Does it work if you move the static_assert into a function scope? If so then > this is probably a dup of PR85944. Yes it does work with: ``` void f1() { static_assert(S{}.f()); } ``` So yes it is a dup. *** This bug has been marked as a duplicate of bug 85944 *** ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-27 17:54 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-07-27 10:06 [Bug c++/110828] New: union constexpr dtor not constexpr when used in member array gccbugbjorn at fahller dot se 2023-07-27 14:22 ` [Bug c++/110828] " ppalka at gcc dot gnu.org 2023-07-27 16:25 ` gccbugbjorn at fahller dot se 2023-07-27 17:54 ` 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).