Index: clang/include/clang/Sema/Sema.h =================================================================== --- clang/include/clang/Sema/Sema.h +++ clang/include/clang/Sema/Sema.h @@ -9456,6 +9456,18 @@ SavedPendingLocalImplicitInstantiations; }; + class PerformPendingInstantiationsRAII { + Sema &S; + public: + PerformPendingInstantiationsRAII(Sema &S): S(S) {} ; + + ~PerformPendingInstantiationsRAII() { + S.PerformPendingInstantiations(); + assert(S.PendingInstantiations.empty() && + "there shouldn't be any pending instantiations"); + } + }; + /// A helper class for building up ExtParameterInfos. class ExtParameterInfoBuilder { SmallVector Infos; Index: clang/lib/Interpreter/IncrementalParser.cpp =================================================================== --- clang/lib/Interpreter/IncrementalParser.cpp +++ clang/lib/Interpreter/IncrementalParser.cpp @@ -177,6 +177,7 @@ } DiagnosticsEngine &Diags = getCI()->getDiagnostics(); + Sema::PerformPendingInstantiationsRAII PerformPendingInstantiations(S); if (Diags.hasErrorOccurred()) { TranslationUnitDecl *MostRecentTU = C.getTranslationUnitDecl(); Index: clang/test/Interpreter/execute.cpp =================================================================== --- clang/test/Interpreter/execute.cpp +++ clang/test/Interpreter/execute.cpp @@ -1,3 +1,5 @@ +// RUN: clang-repl "template T f() { return T(); }" "auto ptu2 = f(); err;" \ +// RUN: "auto ptu2 = f();" "int i = 0;" // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \ // RUN: 'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s // REQUIRES: host-supports-jit