<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/74154>74154</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Bad error message when trying to assign to member of reference type returned from function with deduced return type
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          davidstone
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVF2PqzYQ_TXOy2gRNiRsHnjIfkRaVfepV6r6aPAQXBmb2kP2pg_97ZVt0mRX2w8rMsQcZs7MOYwMQZ8sYsu2T2z7spELjc63Sp61CuQsbjqnLu33EWFwxrh3bU-gjXkYnJ9QAXlpg5GknYXFamLlCysP674r86-f53wSyC89QQDWPF2Re20JJlZdD5qX233a5UIOTkhMPAbonQ0ETOzgBxP7D3E80uJtfPbjQ7S7UGenFQz_FSglzM9n8sCqlzV9RN6R28_kH1j1OiVI9UXSawPuOfRyCRigN9KeIFamzwjSAnrvPEwYgjwhuOHrTjobnMH1tHoObvE9suqVVQfOWXXYs-q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