diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -1176,15 +1176,11 @@ } if (ThisTy.isNull() && isLambdaCallOperator(CurContext) && - inTemplateInstantiation()) { - - assert(isa(DC) && - "Trying to get 'this' type from static method?"); + inTemplateInstantiation() && isa(DC)) { // This is a lambda call operator that is being instantiated as a default // initializer. DC must point to the enclosing class type, so we can recover // the 'this' type from it. - QualType ClassTy = Context.getTypeDeclType(cast(DC)); // There are no cv-qualifiers for 'this' within default initializers, // per [expr.prim.general]p4. diff --git a/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp --- a/clang/test/SemaCXX/lambda-expressions.cpp +++ b/clang/test/SemaCXX/lambda-expressions.cpp @@ -1,6 +1,8 @@ // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify -verify=expected-cxx14 -fblocks %s // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify -fblocks %s +// RUN: %clang_cc1 -std=c++17 -fblocks -DSHOW_MS -Wno-unused-value -fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify %s +#ifndef SHOW_MS namespace std { class type_info; }; namespace ExplicitCapture { @@ -664,3 +666,22 @@ } }; + +#else +template +void Decider(const RT &sp, ET &ep) { + [=](auto i) { ep[i] = sp[i + j]; }; + // expected-error@-1 {{use of undeclared identifier 'j'}} +} + +template void LS() { + int *ep; + Decider(5, ep); +} + +void runChapter4() +{ + LS(); // expected-note {{in instantiation of}} +} + +#endif