[libcxx-commits] [libcxx] Add [[clang::lifetimebound]] to numerous functions in libc++ include headers (PR #112751)

Haojian Wu via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 23 05:10:16 PDT 2024


hokein wrote:

> > By the way - I keep getting [this confusing error](https://github.com/llvm/llvm-project/actions/runs/11472747270/job/31925816201?pr=112751#step:3:4068) in CI, and I'm not sure if I'm decorating something incorrectly. If anyone has an idea, please let me kno
> 
> (I don't have experience with libcxx.) At first glance, this seems like a false positive triggered by the newly introduced lifetimebound annotation. It’s possible that we might have an incorrect annotation somewhere causing this issue.

I think this is caused by the lifetimebound annotation on the `[]` operator of iterator. 
`ranges::begin` returns an iterator, and we access the inner elements using the `[]` operator. Even though the iterator object is destroyed at the end of the full expression, the underlying storage remains valid.

```
  std::vector<int> vv = {1};
  auto & b  = std::ranges::begin(vv)[0]; // false positive
```



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


More information about the libcxx-commits mailing list