[clang] [clang][Sema] Deprecate `global`/`unknown` in `lifetime_capture_by` (PR #196635)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 10 03:45:59 PDT 2026
NeKon69 wrote:
Just checked abseil source, it seems like you are defining them something like this:
```cpp
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::lifetime_capture_by)
#define ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(Owner) \
[[clang::lifetime_capture_by(Owner)]]
#else
#define ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(Owner)
#endif
```
I don't think there's an easy migration path for this, the only thing I can come up with is adding a new macro specifically for global/this/unknown (though maybe there's some C macro magic that I am not aware about). E.g. a separate macro for the this case that prefers the new spelling:
```cpp
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::lifetime_capture_by_this)
#define ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY_THIS \
[[clang::lifetime_capture_by_this]]
#elif ABSL_HAVE_CPP_ATTRIBUTE(clang::lifetime_capture_by)
#define ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY_THIS \
ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(this)
#else
#define ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY_THIS
#endif
```
Then use sites switch from `ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(this)` to `ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY_THIS`.
https://github.com/llvm/llvm-project/pull/196635
More information about the cfe-commits
mailing list