[cfe-commits] r73336 - in /cfe/trunk/lib/Sema: Sema.cpp Sema.h SemaTemplateDeduction.cpp
Douglas Gregor
dgregor at apple.com
Sun Jun 14 01:02:22 PDT 2009
Author: dgregor
Date: Sun Jun 14 03:02:22 2009
New Revision: 73336
URL: http://llvm.org/viewvc/llvm-project?rev=73336&view=rev
Log:
Introduce a SFINAE "trap" that keeps track of the number of errors
that were suppressed due to SFINAE. By checking whether any errors
occur at the end of template argument deduction, we avoid the
possibility of suppressing an error (due to SFINAE) and then
recovering so well that template argument deduction never detects that
there was a problem. Thanks to Eli for the push in this direction.
Modified:
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=73336&r1=73335&r2=73336&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sun Jun 14 03:02:22 2009
@@ -183,7 +183,7 @@
CurBlock(0), PackContext(0), IdResolver(pp.getLangOptions()),
GlobalNewDeleteDeclared(false),
CompleteTranslationUnit(CompleteTranslationUnit),
- CurrentInstantiationScope(0) {
+ NumSFINAEErrors(0), CurrentInstantiationScope(0) {
StdNamespace = 0;
TUScope = 0;
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=73336&r1=73335&r2=73336&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Jun 14 03:02:22 2009
@@ -256,6 +256,9 @@
/// unit.
bool CompleteTranslationUnit;
+ /// \brief The number of SFINAE diagnostics that have been trapped.
+ unsigned NumSFINAEErrors;
+
typedef llvm::DenseMap<Selector, ObjCMethodList> MethodPool;
/// Instance/Factory Method Pools - allows efficient lookup when typechecking
@@ -308,8 +311,25 @@
if (isSFINAEContext() && Diagnostic::isBuiltinSFINAEDiag(DiagID)) {
// If we encountered an error during template argument
// deduction, and that error is one of the SFINAE errors,
- // supress the diagnostic.
- return SemaDiagnosticBuilder(*this);
+ // suppress the diagnostic.
+ bool Fatal = false;
+ switch (Diags.getDiagnosticLevel(DiagID)) {
+ case Diagnostic::Ignored:
+ case Diagnostic::Note:
+ case Diagnostic::Warning:
+ break;
+
+ case Diagnostic::Error:
+ ++NumSFINAEErrors;
+ break;
+
+ case Diagnostic::Fatal:
+ Fatal = true;
+ break;
+ }
+
+ if (!Fatal)
+ return SemaDiagnosticBuilder(*this);
}
DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
@@ -2340,6 +2360,24 @@
/// will be suppressed and there will be no local error recovery.
bool isSFINAEContext() const;
+ /// \brief RAII class used to determine whether SFINAE has
+ /// trapped any errors that occur during template argument
+ /// deduction.
+ class SFINAETrap {
+ Sema &SemaRef;
+ unsigned PrevSFINAEErrors;
+ public:
+ explicit SFINAETrap(Sema &SemaRef)
+ : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors) { }
+
+ ~SFINAETrap() { SemaRef.NumSFINAEErrors = PrevSFINAEErrors; }
+
+ /// \brief Determine whether any SFINAE errors have been trapped.
+ bool hasErrorOccurred() const {
+ return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
+ }
+ };
+
/// \brief A stack-allocated class that identifies which local
/// variable declaration instantiations are present in this scope.
///
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=73336&r1=73335&r2=73336&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Sun Jun 14 03:02:22 2009
@@ -632,6 +632,7 @@
// argument list if the template arguments of the partial
// specialization can be deduced from the actual template argument
// list (14.8.2).
+ SFINAETrap Trap(*this);
llvm::SmallVector<TemplateArgument, 4> Deduced;
Deduced.resize(Partial->getTemplateParameters()->size());
if (TemplateDeductionResult Result
@@ -735,6 +736,9 @@
// FIXME: Check template template arguments?
}
+ if (Trap.hasErrorOccurred())
+ return TDK_SubstitutionFailure;
+
return TDK_Success;
}
More information about the cfe-commits
mailing list