diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -652,9 +652,7 @@ } // Late template parsing can begin. - if (getLangOpts().DelayedTemplateParsing) - Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, - this); + Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this); if (!PP.isIncrementalProcessingEnabled()) Actions.ActOnEndOfTranslationUnit(); //else don't tell Sema that we ended parsing: more input might come. diff --git a/clang/test/PCH/delayed-template-parsing.cpp b/clang/test/PCH/delayed-template-parsing.cpp new file mode 100644 --- /dev/null +++ b/clang/test/PCH/delayed-template-parsing.cpp @@ -0,0 +1,14 @@ +// Check any combination of delayed-template-parsing between PCH and TU works. +// RUN: %clang_cc1 %s -emit-pch -o %t.pch +// RUN: %clang_cc1 -fdelayed-template-parsing %s -emit-pch -o %t.delayed.pch +// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.pch %s +// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch %t.pch %s +// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.delayed.pch %s +// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch %t.delayed.pch %s + +#ifndef MAIN_FILE +template +T successor(T Value) { return Value + 1; } +#else +int x = successor(42); +#endif