llvm / llvm/llvm-project

[LifetimeSafety] Assertion failure on lifetime_capture_by in a member function

Open
#212,231 4 comments 0 reactions 1 assignee Claimed by @kashika0112 View on GitHub
clang:temporal-safety crash-on-valid
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`-Wlifetime-safety` hits an assertion when `[[clang::lifetime_capture_by()]]` names another parameter of a member function:
https://godbolt.org/z/rzqEjvGPf

```c++
// crashes
struct S {
void cap(int *p [[clang::lifetime_capture_by(c)]], int *&c);
};
void use() { S s; int i; int *c; s.cap(&i, c); }
```
```
Assertion `Index < Length && "Invalid index!"' failed.
```

The same signature as a free function or as a static member function does not crash:
```c++
// does not crash
void cap(int *p [[clang::lifetime_capture_by(c)]], int *&c);
void use() { int i; int *c; cap(&i, c); }
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.