[cfe-commits] r66563 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/instantiation-backtrace.cpp
Douglas Gregor
dgregor at apple.com
Tue Mar 10 11:52:44 PDT 2009
Author: dgregor
Date: Tue Mar 10 13:52:44 2009
New Revision: 66563
URL: http://llvm.org/viewvc/llvm-project?rev=66563&view=rev
Log:
If we run into multiple errors within the same template instantiation,
only print the template instantiation backtrace for the first error.
Also, if a base class has failed to type-check during instantiation,
just drop that base class and continue on to check other base classes.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/SemaTemplate/instantiation-backtrace.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=66563&r1=66562&r2=66563&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Mar 10 13:52:44 2009
@@ -243,7 +243,10 @@
/// The primitive diagnostic helpers.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
- if (!Diags.isBuiltinNote(DiagID) && !ActiveTemplateInstantiations.empty())
+ if (!Diags.isBuiltinNote(DiagID) &&
+ !ActiveTemplateInstantiations.empty() &&
+ ActiveTemplateInstantiations.back().Entity
+ != LastTemplateInstantiationErrorContext)
DB << PostDiagnosticHook(PrintInstantiationStackHook, this);
return DB;
}
@@ -1691,6 +1694,15 @@
llvm::SmallVector<ActiveTemplateInstantiation, 16>
ActiveTemplateInstantiations;
+ /// \brief The last template from which a template instantiation
+ /// error or warning was produced.
+ ///
+ /// This value is used to suppress printing of redundant template
+ /// instantiation backtraces when there are multiple errors in the
+ /// same instantiation. FIXME: Does this belong in Sema? It's tough
+ /// to implement it anywhere else.
+ ClassTemplateSpecializationDecl *LastTemplateInstantiationErrorContext;
+
/// \brief A stack object to be created when performing template
/// instantiation.
///
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=66563&r1=66562&r2=66563&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue Mar 10 13:52:44 2009
@@ -56,7 +56,10 @@
/// \brief Post-diagnostic hook for printing the instantiation stack.
void Sema::PrintInstantiationStackHook(unsigned, void *Cookie) {
- static_cast<Sema*>(Cookie)->PrintInstantiationStack();
+ Sema &SemaRef = *static_cast<Sema*>(Cookie);
+ SemaRef.PrintInstantiationStack();
+ SemaRef.LastTemplateInstantiationErrorContext
+ = SemaRef.ActiveTemplateInstantiations.back().Entity;
}
/// \brief Prints the current instantiation stack through a series of
@@ -503,7 +506,7 @@
for (ClassTemplateSpecializationDecl::base_class_iterator
Base = ClassTemplate->getTemplatedDecl()->bases_begin(),
BaseEnd = ClassTemplate->getTemplatedDecl()->bases_end();
- Base != BaseEnd && !Invalid; ++Base) {
+ Base != BaseEnd; ++Base) {
if (!Base->getType()->isDependentType()) {
// FIXME: Allocate via ASTContext
InstantiatedBases.push_back(new CXXBaseSpecifier(*Base));
@@ -533,7 +536,8 @@
Invalid = true;
}
- if (AttachBaseSpecifiers(ClassTemplateSpec, &InstantiatedBases[0],
+ if (!Invalid &&
+ AttachBaseSpecifiers(ClassTemplateSpec, &InstantiatedBases[0],
InstantiatedBases.size()))
Invalid = true;
Modified: cfe/trunk/test/SemaTemplate/instantiation-backtrace.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiation-backtrace.cpp?rev=66563&r1=66562&r2=66563&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiation-backtrace.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiation-backtrace.cpp Tue Mar 10 13:52:44 2009
@@ -1,5 +1,5 @@
// RUN: clang -fsyntax-only -verify %s
-template<typename T> struct A; // expected-note 2{{template is declared here}}
+template<typename T> struct A; // expected-note 4{{template is declared here}}
template<typename T> struct B : A<T*> { }; // expected-error{{implicit instantiation of undefined template}} \
// expected-error{{implicit instantiation of undefined template 'struct A<X *>'}}
@@ -21,3 +21,12 @@
void g() {
(void)sizeof(B<X>); // expected-note{{in instantiation of template class 'struct B<X>' requested here}}
}
+
+template<typename T>
+struct G : A<T>, // expected-error{{implicit instantiation of undefined template 'struct A<int>'}}
+ A<T*> // expected-error{{implicit instantiation of undefined template 'struct A<int *>'}}
+ { };
+
+void h() {
+ (void)sizeof(G<int>); // expected-note{{in instantiation of template class 'struct G<int>' requested here}}
+}
More information about the cfe-commits
mailing list