diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 59b8c9b60663c..146dd7e78a27c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2125,8 +2125,11 @@ static Decl *getPredefinedExprDecl(Sema &S, DeclContext *DC) { while (LSI != E && isa(*LSI) && !isa(*LSI)) ++LSI; - assert(LSI != E && "Should be in a lambda scope info"); - if (dyn_cast(*LSI)->BeforeCompoundStatement) + if (LSI == E || !isa(*LSI)) { + // The lambda scope may already be popped during delayed parsing. + return; + } + if (cast(*LSI)->BeforeCompoundStatement) DC = DC->getParent(); ++LSI; } diff --git a/clang/test/SemaCXX/GH213420.cpp b/clang/test/SemaCXX/GH213420.cpp new file mode 100644 index 0000000000000..2d1b9f032e7e4 --- /dev/null +++ b/clang/test/SemaCXX/GH213420.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fms-compatibility -verify \ +// RUN: -Wno-missing-declarations -Wno-unused-value %s + +void foo() { + [] { + struct { // expected-error {{anonymous structs and classes must be class members}} + void bar(int & = "") {} // expected-error {{non-const lvalue reference to type 'int' cannot bind}} + // expected-note@-1 {{passing argument to parameter here}} + // expected-error@-2 {{functions cannot be declared in an anonymous struct}} + }; + }; +}