From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DC2E93836C09; Mon, 2 Nov 2020 17:30:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC2E93836C09 From: "ldalessandro at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr Date: Mon, 02 Nov 2020 17:30:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: ldalessandro at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Nov 2020 17:30:44 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97665 --- Comment #4 from Luke Dalessandro --- Hi Jakob, Thank you for looking at this. I restructured the code sample according to = your suggestions and it is available here https://godbolt.org/z/P1bMEz. I don't understand a couple of things that you said, and ultimately I'm not sure if= you are agreeing that this could be a bug. > You can do Foo foo =3D Foo(); and it compiles. 1. I can't do `Foo foo =3D Foo();` because the purpose of the union is to allocate uninitialized storage for the `Foo` during `constexpr` execution w= hen `Foo` has no default constructor. I realize now I meant to write `constexpr Foo() =3D delete;` in the original code. I _can_ use the monostate to have = an active member at initialization, but would prefer not to as it complicates = the union.=20 > clang++ rejects it too: > error: constexpr union constructor that does not initialize any member is= a=20 > C++20 extension [-Werror,-Wc++20-extensions] though only with -pedantic-e= rrors. 2. I can't get clang to emit the warning you describe even with the provided flags, perhaps I am doing it wrong or misinterpreting your comment. > P1331R2 support is there since=20 > r10-5194-g7906797ebec6881d7d90165340f51efcf447d716=20 > (so without [1] it is accepted for -std=3Dc++2a since that revision) 3. I think this means that, if the member is not an array, then it is accep= ted with `-std=3Dc++2a`. I do observe this, however it's not my use case. Techn= ically I have an array of some class template parameter `N`. The updated test case with the deleted constructor is. ``` struct Foo { constexpr Foo() =3D delete; }; union U { // struct {} monostate =3D {}; Foo foo; constexpr U() {} }; struct V { U storage[1]; }; constexpr V v; ```=