Skip to content
Merged
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
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ Bug Fixes to C++ Support
- Diagnose unresolved overload sets in non-dependent compound requirements. (#GH51246) (#GH97753)
- Fix a crash when extracting unavailable member type from alias in template deduction. (#GH165560)
- Fix incorrect diagnostics for lambdas with init-captures inside braced initializers. (#GH163498)
- Fixed spurious diagnoses of certain nested lambda expressions. (#GH149121) (#GH156579)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15628,6 +15628,8 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
DC = DC->getParent();
if ((getSema().isUnevaluatedContext() ||
getSema().isConstantEvaluatedContext()) &&
!(dyn_cast_or_null<CXXRecordDecl>(DC->getParent()) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'd want to use isa_and_present (or isa_and_nonnull or w/e it is called) in this case.

That said, we probably would prefer to do something like extracting above the if a const auto *RD = dyn_cast_if_present<CXXRecordDecl>(DC->getParent()); then changing the check to RD && RD->isGenericLambda()` (or perhaps BETTER, pulling that whole thing out to a separate boolean with a reasonable name, so you have a place to put a comment).

Which brings me to the last thing, I'd like a comment explaining WHY this check should be here, it looks enough out of place as to why this cannot be dependent.

cast<CXXRecordDecl>(DC->getParent())->isGenericLambda()) &&
(DC->isFileContext() || !DC->getParent()->isDependentContext()))
DependencyKind = CXXRecordDecl::LDK_NeverDependent;

Expand Down
23 changes: 22 additions & 1 deletion clang/test/SemaCXX/cxx2a-consteval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,27 @@ namespace GH139160{
B result = (B){10, get_value(make_struct())}; // expected-error {{initializer element is not a compile-time constant}}
// expected-error@-1 {{call to consteval function 'GH139160::get_value' is not a constant expression}}
// expected-note@-2 {{non-constexpr function 'make_struct' cannot be used in a constant expression}}
};
} // namespace GH139160

namespace GH118187 {

template <typename T> int t() {
return []<typename U>() consteval {
return [](U v) { return v; }(123);
}.template operator()<int>();
}

int v = t<int>();
} // namespace GH118187

namespace GH156579 {
template <class>
auto f{[] (auto...) {
if constexpr ([] (auto) { return true; }(0))
return 0;
}};

void g() {
f<int>();
}
} // namespace GH156579