Issue |
95992
|
Summary |
[clang] wrong decltype results for a reference captured by value
|
Labels |
clang
|
Assignees |
|
Reporter |
mmatrosov
|
Consider the following program (https://godbolt.org/z/8EY4G3n68):
```
int main() {
int i = 0;
const int& ir = i;
auto f = [ir] mutable -> const int& {
// ir = 13; error
static_assert(!std::is_const_v<decltype(ir)>);
static_assert(std::is_reference_v<decltype(ir)>);
return ir;
};
return &ir == &f();
}
```
Here `ir` is a const ref captured by value. It is represented by `const int` member in the closure object (https://eel.is/c++draft/expr.prim.lambda.capture#10):
> For each entity captured by copy, an unnamed non-static data member is declared in the closure type. The type of such a data member is the *referenced type* if the entity is a reference to an object
(I personally see no reason why `const` qualifier should not be stripped off during capture, but this is another story)
The line `ir = 13` does not compile with the error `cannot assign to a variable captured by copy in a non-mutable lambda` which clearly tells that the type is not `int` (and the error is a bit misleading, since the lambda is marked `mutable`). The return code of the program is zero, which tells that the type is not a reference.
However, both `static_asserts` compile, saying `ir` within the closure is a reference, and is non-const. As if they were applied to the outer `ir` in the body of the function.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs