[clang] [clang] Merge lifetimebound and GSL code paths for lifetime analysis (PR #104906)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 23 02:50:03 PDT 2024


hokein wrote:

The removal of `EnableLifetimeWarnings` flag causes some behavior change when we visit a lifetimebound function argument:

- before: the `EnableLifetimeWarnings` is always `false`, which means we never run into the GSL codepath
- after: we remove this flag, we will continue to run the GSL codepath (unless the GSL diagnostic is disabled)

For the following case,
```
struct Foo;
struct FooView {
  FooView(const Foo& foo [[clang::lifetimebound]]);
};
struct Foo {};

FooView test() {
  return std::vector<Foo>()[0]; // dangling
}
```

We start to emit a dangling diagnostic after this change, this looks like a good change as we catch more cases now.

Still need to look at the libcxx failure.

https://github.com/llvm/llvm-project/pull/104906


More information about the cfe-commits mailing list