[Bug c++/97195] New: construct_at on a union member is not a constant expression
barry.revzin at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Sep 24 14:37:47 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97195
Bug ID: 97195
Summary: construct_at on a union member is not a constant
expression
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: barry.revzin at gmail dot com
Target Milestone: ---
In trying to test adding more constexpr support to std::optional:
#include <bits/stl_construct.h>
union S {
int i;
};
constexpr int f() {
S s;
std::construct_at(&s.i, 0);
return 0;
}
constexpr int z = f();
gcc rejects with:
<source>:13:20: in 'constexpr' expansion of 'f()'
<source>:9:22: in 'constexpr' expansion of 'std::construct_at<int, int>((&
s.S::i), 0)'
<source>:13:21: error: '(void*)(& s.S::i)' is not a constant expression
13 | constexpr int z = f();
| ^
But this should be fine.
More information about the Gcc-bugs
mailing list