* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
@ 2020-11-01 17:31 ` ldalessandro at gmail dot com
2020-11-02 11:55 ` jakub at gcc dot gnu.org
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ldalessandro at gmail dot com @ 2020-11-01 17:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
--- Comment #1 from Luke Dalessandro <ldalessandro at gmail dot com> ---
(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.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
2020-11-01 17:31 ` [Bug c++/97665] " ldalessandro at gmail dot com
@ 2020-11-02 11:55 ` jakub at gcc dot gnu.org
2020-11-02 12:24 ` jakub at gcc dot gnu.org
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-02 11:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
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
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
2020-11-01 17:31 ` [Bug c++/97665] " ldalessandro at gmail dot com
2020-11-02 11:55 ` jakub at gcc dot gnu.org
@ 2020-11-02 12:24 ` jakub at gcc dot gnu.org
2020-11-02 17:30 ` ldalessandro at gmail dot com
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-02 12:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
P1331R2 support is there since
r10-5194-g7906797ebec6881d7d90165340f51efcf447d716 (so without [1] it is
accepted for -std=c++2a since that revision).
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
` (2 preceding siblings ...)
2020-11-02 12:24 ` jakub at gcc dot gnu.org
@ 2020-11-02 17:30 ` ldalessandro at gmail dot com
2020-11-02 17:37 ` ldalessandro at gmail dot com
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ldalessandro at gmail dot com @ 2020-11-02 17:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
--- Comment #4 from Luke Dalessandro <ldalessandro at gmail dot com> ---
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;
```
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
` (3 preceding siblings ...)
2020-11-02 17:30 ` ldalessandro at gmail dot com
@ 2020-11-02 17:37 ` ldalessandro at gmail dot com
2020-11-02 17:42 ` jakub at gcc dot gnu.org
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ldalessandro at gmail dot com @ 2020-11-02 17:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
--- Comment #5 from Luke Dalessandro <ldalessandro at gmail dot com> ---
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<T*>` might be
used during normal execution.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
` (4 preceding siblings ...)
2020-11-02 17:37 ` ldalessandro at gmail dot com
@ 2020-11-02 17:42 ` jakub at gcc dot gnu.org
2020-11-02 17:49 ` ldalessandro at gmail dot com
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-02 17:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
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.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
` (5 preceding siblings ...)
2020-11-02 17:42 ` jakub at gcc dot gnu.org
@ 2020-11-02 17:49 ` ldalessandro at gmail dot com
2021-08-04 17:06 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ldalessandro at gmail dot com @ 2020-11-02 17:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
--- Comment #7 from Luke Dalessandro <ldalessandro at gmail dot com> ---
Thank you, sorry for the confusion.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
` (6 preceding siblings ...)
2020-11-02 17:49 ` ldalessandro at gmail dot com
@ 2021-08-04 17:06 ` pinskia at gcc dot gnu.org
2021-09-01 21:12 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04 17:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-08-04
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
` (7 preceding siblings ...)
2021-08-04 17:06 ` pinskia at gcc dot gnu.org
@ 2021-09-01 21:12 ` pinskia at gcc dot gnu.org
2022-11-22 7:37 ` dysnomia.eris at online dot de
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-01 21:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The array is not needed to reproduce this though:
struct Foo {
constexpr Foo() {}
};
union U {
// struct {} monostate = {};
Foo foo;
constexpr U() {}
};
constexpr U s;
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
` (8 preceding siblings ...)
2021-09-01 21:12 ` pinskia at gcc dot gnu.org
@ 2022-11-22 7:37 ` dysnomia.eris at online dot de
2022-11-23 2:17 ` de34 at live dot cn
2023-06-14 4:02 ` pinskia at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: dysnomia.eris at online dot de @ 2022-11-22 7:37 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
` (9 preceding siblings ...)
2022-11-22 7:37 ` dysnomia.eris at online dot de
@ 2022-11-23 2:17 ` de34 at live dot cn
2023-06-14 4:02 ` pinskia at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: de34 at live dot cn @ 2022-11-23 2:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
Jiang An <de34 at live dot cn> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |de34 at live dot cn
--- Comment #11 from Jiang An <de34 at live dot cn> ---
This looks like CWG issue 2558 (currently unresolved).
https://cplusplus.github.io/CWG/issues/2558.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97665] constexpr union array member incorrectly rejected as non-constexpr
2020-11-01 17:29 [Bug c++/97665] New: constexpr union array member incorrectly rejected as non-constexpr ldalessandro at gmail dot com
` (10 preceding siblings ...)
2022-11-23 2:17 ` de34 at live dot cn
@ 2023-06-14 4:02 ` pinskia at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-14 4:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97665
--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(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 ...
^ permalink raw reply [flat|nested] 13+ messages in thread