Issue 126600
Summary False positive lifetime GSL warning for no-capture lambda?
Labels clang:diagnostics
Assignees
Reporter smeenai
    For the code in https://godbolt.org/z/v919qqe6o:

```
struct [[gsl::Pointer]] function_ref {
  template <typename Callable>
  function_ref(Callable &&callable [[clang::lifetimebound]]) : ref(callable) {}
  void (*ref)();
};

void f();
void g(function_ref &r) {
  r = []() { f(); };
}
```

Clang trunk produces a warning:
```
warning: object backing the pointer r will be destroyed at the end of the full-_expression_ [-Wdangling-assignment-gsl]
    9 |   r = []() { f(); };
```

Clang seems to consider the no-capture lambda as a temporary that will be destroyed at the end of the _expression_. I'm not a standards expert and I haven't found anything definitive through searching, but in practice no-capture lambdas will turn into ordinary functions, so there's no actual issue here. Should we actually be warning for this?

https://github.com/llvm/llvm-project/commit/a3b4d9147406cbd90090466a9b2b9bb2e9f6000c is a commit that ran into this and changed the code slightly to avoid it (the code change made there would result in a stack-use-after-free were this an actual issue, but it avoids the warning). https://github.com/llvm/llvm-project/pull/126140 is a high-firing instance of this warning, and we'd appreciate some guidance.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to