Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ Bug Fixes in This Version
- Fixed a failed assertion with empty filename arguments in ``__has_embed``. (#GH159898)
- Fixed a failed assertion with empty filename in ``#embed`` directive. (#GH162951)
- Fixed a crash triggered by unterminated ``__has_embed``. (#GH162953)
- Fixed a wrong diagnostic about a local variable inside a lambda in unevaluated
context needs capture. (#GH163837)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Comment on lines +7065 to +7068
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find ternary operator inside of an if uncommon, can we simply do

Suggested change
if (auto Found =
CurrentInstantiationScope
? CurrentInstantiationScope->getInstantiationOfIfExists(D)
: nullptr) {
if (CurrentInstantiationScope) {
llvm::PointerUnion<... > * Found = CurrentInstantiationScope->getInstantiationOfIfExists(D)
...

and spell out the type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

FooType *MyFoo /* ugh capitalization style */ = someRandoFunction();
auto *MyBar = dyn_cast<Bar>(expression);
auto *MyOtherThing = expression->getAsMyOtherThing();

return cast<NamedDecl>(Found->dyn_cast<Decl *>());
Copy link
Contributor

@Fznamznon Fznamznon Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using of dyn_cast is strange here IMO, since the outer cast doesn't expect null. If that is always a Decl there, we probably need to use get instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast_or_null would be appropriate

}
return D;
}

ParentDC = FindInstantiatedContext(Loc, ParentDC, TemplateArgs);
if (!ParentDC)
Expand Down
19 changes: 19 additions & 0 deletions clang/test/SemaCXX/lambda-unevaluated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,22 @@ static_assert(__is_same_as(int, helper<int>));


} // namespace GH138018

namespace GH163837 {

template<int N>
void f();

template<class>
struct X {
using type = decltype([](auto) {
f<[]{
int result = 0;
return result;
}()>();
}(0));
};

X<void> l;

} // namespace GH163837