From: Akira Hatanaka Date: Thu, 3 Nov 2016 15:04:58 +0000 (+0000) Subject: [Sema] Avoid instantiating templates only when UncompilableErrorOccurred X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2be8d26c6cbcab5338dfc766b1e42c760afd0994;p=clang [Sema] Avoid instantiating templates only when UncompilableErrorOccurred and FatalErrorOccurred are both set. This fixes a crash that occurs when a warning promoted to a fatal error leaves the AST in an incomplete state, and then later CFG analysis is run on the incomplete AST. rdar://problem/28558923 Differential Revision: https://reviews.llvm.org/D26166 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285923 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index b715c13b07..6e715d25b4 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -209,9 +209,11 @@ Sema::InstantiatingTemplate::InstantiatingTemplate( sema::TemplateDeductionInfo *DeductionInfo) : SemaRef(SemaRef), SavedInNonInstantiationSFINAEContext( SemaRef.InNonInstantiationSFINAEContext) { - // Don't allow further instantiation if a fatal error has occcured. Any - // diagnostics we might have raised will not be visible. - if (SemaRef.Diags.hasFatalErrorOccurred()) { + // Don't allow further instantiation if a fatal error and an uncompilable + // error have occcured. Any diagnostics we might have raised will not be + // visible, and we do not need to construct a correct AST. + if (SemaRef.Diags.hasFatalErrorOccurred() && + SemaRef.Diags.hasUncompilableErrorOccurred()) { Invalid = true; return; } diff --git a/test/SemaCXX/instantiate-template-fatal-error.cpp b/test/SemaCXX/instantiate-template-fatal-error.cpp new file mode 100644 index 0000000000..9c8916e77b --- /dev/null +++ b/test/SemaCXX/instantiate-template-fatal-error.cpp @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s + +#pragma clang diagnostic fatal "-Wall" +#pragma clang diagnostic fatal "-Wold-style-cast" + +template bool foo0(const long long *a, T* b) { + return a == (const long long*)b; // expected-error {{use of old-style cast}} +} + +template +struct S1 { +}; + +template +struct S2 : S1 { + bool m1(const long long *a, T *b) const { return foo0(a, b); } +}; + +bool foo1(const long long *a, int *b) { + S2 s2; + return s2.m1(a, b); +}