https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99622
Bug ID: 99622
Summary: Materialized temporary is not usable in a constant
expression
Product: gcc
Version: 11.0
URL: https://godbolt.org/z/M4Ya9h
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: johelegp at gmail dot com
CC: johelegp at gmail dot com
Target Milestone: ---
See https://godbolt.org/z/M4Ya9h.
```C++
const bool& b = bool{true};
static_assert(b);
```
```
<source>:2:15: error: non-constant condition for static assertion
2 | static_assert(b);
| ^
<source>:2:15: error: the value of '<temporary>' is not usable in a constant
expression
<source>:1:26: note: 'bool <temporary>' is not const
1 | const bool& b = bool{true};
| ^
Compiler returned: 1
```
```C++
struct A { bool b{true}; };
const A& a = A{};
static_assert(a.b);
```
```
<source>:3:17: error: non-constant condition for static assertion
3 | static_assert(a.b);
| ~~^
<source>:3:17: error: the value of '<temporary>' is not usable in a constant
expression
<source>:2:16: note: '<temporary>' was not declared 'constexpr'
2 | const A& a = A{};
| ^
Compiler returned: 1
```