Issue 162649
Summary `getReturnTypeSourceRange()` returns invalid `SourceRange` for trailing return type functions
Labels new issue
Assignees
Reporter bricknerb
    This probably effects a lot of code that uses trailing return type syntax.

To make it easily reproducible, I looked at this use case:
https://github.com/llvm/llvm-project/blob/4f80c064eb2933c00c0ba9b7826aa3631cf3b5c2/clang/test/SemaCXX/err_typecheck_assign_const.cpp#L32

With trailing return type it generates the note **without a location**.

Not using trailing return types:

```c++
const int& good();
void test_good() { good() = 10; }
```

Diagnoses with

```
<source>:2:27: error: cannot assign to return value because function 'good' returns a const value
    2 | void test_good() { good() = 10; }
      |                    ~~~~~~ ^
<source>:1:7: note: function 'good' which returns const-qualified type 'const int &' declared here
    1 | const int& good();
      | ^~~~
1 error generated.
Compiler returned: 1
```

However, using trialing return types:

```c++
auto bad() -> const int&;
void test_bad() { bad() = 10; }
```

Diagnoses with
```
<source>:2:25: error: cannot assign to return value because function 'bad' returns a const value
    2 | void test_bad() { bad() = 10; }
      |                   ~~~~~ ^
note: function 'bad' which returns const-qualified type 'const int &' declared here
1 error generated.
Compiler returned: 1
```

See https://godbolt.org/z/nn4KTYceW
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to