[clang] [Clang] Fix a wrong diagnostic about a local variable inside a lambda in unevaluated context need capture (PR #165098)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 29 20:26:32 PDT 2025
================
@@ -7061,8 +7061,15 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
// anonymous unions in class templates).
}
- if (!ParentDependsOnArgs)
+ if (!ParentDependsOnArgs) {
+ if (auto Found =
+ CurrentInstantiationScope
+ ? CurrentInstantiationScope->getInstantiationOfIfExists(D)
+ : nullptr) {
----------------
ojhunt wrote:
We really need an equivalent to `.?` in C++ :D
More seriously though, embedding conditional logic inside conditions is difficult to read, so we stick to reasonably linear boolean operations.
I pondered this for a bit an I think agree with @Fznamznon's proposal with an early return `if (!Found)`.
As for the use of `auto` - as a general rule if the type is not mentioned explicitly on the RHS, you should make it explicit in the variable declaration.
i.e
```cpp
FooType *MyFoo /* ugh capitalization style */ = someRandoFunction();
auto *MyBar = dyn_cast<Bar>(expression);
auto *MyOtherThing = expression->getAsMyOtherThing();
```
https://github.com/llvm/llvm-project/pull/165098
More information about the cfe-commits
mailing list