[clang] [Sema] Fix lifetime extension for temporaries in range-based for loops in C++23 (PR #145164)
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 30 04:16:33 PDT 2025
================
@@ -1341,6 +1341,14 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
}
if (IsGslPtrValueFromGslTempOwner && DiagLoc.isValid()) {
+
+ if (SemaRef.getLangOpts().CPlusPlus23) {
----------------
hokein wrote:
the analysis is done here, and we filter out the result. I think we can filter out this case before (in `checkExprLifetimeImpl`) running the analysis to save some cost.
Can you add a testcase (for the `lifetimebound` attr)? Make sure we don't warn on it
```
using size_t = decltype(sizeof(void *));
namespace my_ns {
template <typename T> struct vector {
T &operator[](size_t I) [[clang::lifetimebound]];
};
struct string {
const char *begin();
const char *end();
};
} // namespace std
my_ns::vector<my_ns::string> getData();
void foo() {
for (auto c : getData()[0]) {
(void)c;
}
}
```
https://github.com/llvm/llvm-project/pull/145164
More information about the cfe-commits
mailing list