[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 --- Comment #12 from Andrew Pinski --- (In reply to Jiang An from comment #11) > This looks like CWG issue 2558 (currently unresolved). > > https://cplusplus.github.io/CWG/issues/2558.html It was voted in a few months after this comment was added. But the original testcase has no scalars ...
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 Jiang An changed: What|Removed |Added CC||de34 at live dot cn --- Comment #11 from Jiang An --- This looks like CWG issue 2558 (currently unresolved). https://cplusplus.github.io/CWG/issues/2558.html
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 dysnomia.eris at online dot de changed: What|Removed |Added CC||dysnomia.eris at online dot de --- Comment #10 from dysnomia.eris at online dot de --- Confirmed.
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 --- Comment #9 from Andrew Pinski --- The array is not needed to reproduce this though: struct Foo { constexpr Foo() {} }; union U { // struct {} monostate = {}; Foo foo; constexpr U() {} }; constexpr U s;
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 Andrew Pinski changed: What|Removed |Added Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed||2021-08-04 --- Comment #8 from Andrew Pinski --- Confirmed.
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 --- Comment #7 from Luke Dalessandro --- Thank you, sorry for the confusion.
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 --- Comment #6 from Jakub Jelinek --- All I'm saying is that I believe your code is not valid C++17, but is valid C++20 and that for C++20 we have a compiler bug we need to fix.
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 --- Comment #5 from Luke Dalessandro --- Ugh... replying to myself. > You can do Foo foo = Foo(); and it compiles. >> 1. I can't do `Foo foo = Foo();` because the purpose of the union is to >> allocate uninitialized storage for the `Foo` during `constexpr` execution >> when `Foo` has no default constructor. I realize now I meant to write >> `constexpr Foo() = delete;`. This means to say "trivial default constructor," not just "default constructor". The empty default constructor was an adequate test case for this, but is misleading. The `= delete` should be more effective as an example. The context for the use is to create an array that provides uninitialized vector storage during `constexpr` evaluation in the same way a `std::byte[T*sizeof(T)]` array combined with `reinterptret_cast` might be used during normal execution.
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 --- 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 = Foo(); and it compiles. 1. I can't do `Foo foo = Foo();` because the purpose of the union is to allocate uninitialized storage for the `Foo` during `constexpr` execution when `Foo` has no default constructor. I realize now I meant to write `constexpr Foo() = 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. > clang++ rejects it too: > error: constexpr union constructor that does not initialize any member is a > C++20 extension [-Werror,-Wc++20-extensions] though only with > -pedantic-errors. 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 > r10-5194-g7906797ebec6881d7d90165340f51efcf447d716 > (so without [1] it is accepted for -std=c++2a since that revision) 3. I think this means that, if the member is not an array, then it is accepted with `-std=c++2a`. I do observe this, however it's not my use case. Technically I have an array of some class template parameter `N`. The updated test case with the deleted constructor is. ``` struct Foo { constexpr Foo() = delete; }; union U { // struct {} monostate = {}; Foo foo; constexpr U() {} }; struct V { U storage[1]; }; constexpr V v; ```
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 Jakub Jelinek changed: What|Removed |Added CC||mpolacek at gcc dot gnu.org --- Comment #3 from Jakub Jelinek --- P1331R2 support is there since r10-5194-g7906797ebec6881d7d90165340f51efcf447d716 (so without [1] it is accepted for -std=c++2a since that revision).
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #2 from Jakub Jelinek --- You can do Foo foo = Foo(); and it compiles. clang++ rejects it too: error: constexpr union constructor that does not initialize any member is a C++20 extension [-Werror,-Wc++20-extensions] though only with -pedantic-errors. But g++ rejects it even in -std=c++20 mode: pr97665.C:15:13: error: ‘V{U [1]{U()}}’ is not a constant expression 15 | constexpr V v; | ^ pr97665.C:15:13: error: ‘V()’ is not a constant expression because it refers to an incompletely initialized variable
[Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665 --- Comment #1 from Luke Dalessandro --- (In reply to Luke Dalessandro from comment #0) > GCC currently rejects the following code snippet, where it infers the > constexpr definition of V as non-constexpr. The definition of `v`, not the type `V`. I apologize.