[Bug c++/85944] New: Address of member variable of temporary not considered constexpr at global scope
david at doublewise dot net
gcc-bugzilla@gcc.gnu.org
Mon May 28 04:36:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85944
Bug ID: 85944
Summary: Address of member variable of temporary not considered
constexpr at global scope
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: david at doublewise dot net
Target Milestone: ---
When compiling the following code in C++11, C++14, C++17, or C++2a with 8.1 or
trunk (not tested with earlier versions):
struct S {
int x = 0;
};
constexpr bool f(S const & s) {
return &s.x;
}
constexpr auto x = f(S{});
gcc gives this error message:
<source>:6:12: error: '((&<anonymous>.S::x) != 0)' is not a constant expression
return &s.x;
^
Compiler returned: 1
Putting the declaration of `x` inside a function rather than at global scope
fixes the error, as does creating a constexpr variable to store the result of
`S{}` and then passing that to `f`.
More information about the Gcc-bugs
mailing list