| Issue |
74154
|
| Summary |
Bad error message when trying to assign to member of reference type returned from function with deduced return type
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
davidstone
|
The following ill-formed translation unit
```cpp
struct s {
int m;
};
auto get(s const & x) {
return &x;
}
void f(s const & x) {
auto const ptr = get(x);
ptr->m = 3;
}
```
causes clang to give an error message of
```console
<source>:11:9: error: cannot assign to variable 'ptr' with const-qualified type 'const const s *'
11 | ptr->m = 3;
| ~~~~~~ ^
<source>:10:13: note: variable 'ptr' declared const here
10 | auto const ptr = get(x);
| ~~~~~~~~~~~^~~~~~~~~~~~
1 error generated.
Compiler returned: 1
```
See it live: https://godbolt.org/z/WMMKo7hYe
This has multiple issues:
1. The type is printed incorrectly: it should print `const s * const`.
2. It claims I'm assigning to the variable `ptr`, when I am assigning to a member of the structure pointed to by `ptr`. This causes...
3. It says `ptr` was declared at a location other than its declaration.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs