Issue 180344
Summary Wlifetime-safety-suggestions fixit puts attribute into wrong places
Labels new issue
Assignees
Reporter emaxx-google
    One case when this happens is unnamed function parameters:

```shell
$ cat a.h
#include <ostream>
struct A {};
std::ostream& operator<<(std::ostream&, const A&);
$ cat a.cc
#include "a.h"
std::ostream& operator<<(std::ostream& str, const A&) {
  return str;
}
$ clang++ -Wlifetime-safety -Wlifetime-safety-suggestions -Xclang -fixit a.cc
In file included from a.cc:1:
./a.h:3:26: warning: parameter in cross-TU function should be marked [[clang::lifetimebound]] [-Wlifetime-safety-cross-tu-suggestions]
    3 | std::ostream& operator<<(std::ostream&, const A&);
      | ^~~~~~~~~~~~~
      | [[clang::lifetimebound]]
./a.h:3:26: note: FIX-IT applied suggested code changes
a.cc:3:10: note: param returned here
    3 |   return str;
      | ^~~
1 warning generated.
$ cat a.h
#include <ostream>
struct A {};
std::ostream& operator<<(std::ostream& [[clang::lifetimebound]], const A&);
$ clang++ a.cc
In file included from a.cc:1:
./a.h:3:42: error: 'clang::lifetimebound' attribute only applies to parameters and implicit object parameters
    3 | std::ostream& operator<<(std::ostream& [[clang::lifetimebound]], const A&);
      | ^
```

Another case is a method with a trailing return type - the attribute gets added after the return type where it's not recognized, e.g.:

```c++
auto Foo() -> decltype(0) [[clang::lifetimebound]] {  // error: 'clang::lifetimebound' attribute only applies to parameters and implicit object parameters
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to