Issue |
95225
|
Summary |
Capturing constant bit-field by reference is not a constant _expression_
|
Labels |
new issue
|
Assignees |
|
Reporter |
Fedr
|
This program:
```
struct U {
int i : 4;
};
constexpr int foo() {
const auto & [y] = U{5};
return [&]() { return y; }();
}
static_assert( foo() == 5 );
```
is accepted by GCC, but Clang rejects it with the error:
```
error: static assertion _expression_ is not an integral constant _expression_
10 | static_assert( foo() == 5 );
| ^~~~~~~~~~
note: initializer of '[y]' is not a constant _expression_
6 | const auto & [y] = U{5};
| ^
note: in call to '[&]() {
```
Online demo: https://gcc.godbolt.org/z/Mqx1M9589
If one removes lambda _expression_ then the compilation succeeds, meaning that error about `initializer of '[y]' is not a constant _expression_` is wrong.
The code is slightly modified version from: https://stackoverflow.com/q/78611419/7325599
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs