diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 63930f43c25e3..8161ccdffca82 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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 ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index c2491489f40d2..0e8b674a006d0 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -15628,6 +15628,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr *E) { DC = DC->getParent(); if ((getSema().isUnevaluatedContext() || getSema().isConstantEvaluatedContext()) && + !(dyn_cast_or_null(DC->getParent()) && + cast(DC->getParent())->isGenericLambda()) && (DC->isFileContext() || !DC->getParent()->isDependentContext())) DependencyKind = CXXRecordDecl::LDK_NeverDependent; diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp b/clang/test/SemaCXX/cxx2a-consteval.cpp index 1474c48cda3c1..92bfa40caec4e 100644 --- a/clang/test/SemaCXX/cxx2a-consteval.cpp +++ b/clang/test/SemaCXX/cxx2a-consteval.cpp @@ -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 int t() { + return []() consteval { + return [](U v) { return v; }(123); + }.template operator()(); +} +int v = t(); +} // namespace GH118187 +namespace GH156579 { +template +auto f{[] (auto...) { + if constexpr ([] (auto) { return true; }(0)) + return 0; +}}; + +void g() { + f(); +} +} // namespace GH156579