Make sure template argument deduction is consistently performed in an unevaluated context.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150049 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index 596326c..9d71100 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -2019,7 +2019,8 @@
                                 const TemplateArgumentList &TemplateArgs,
                       SmallVectorImpl<DeducedTemplateArgument> &Deduced,
                                 TemplateDeductionInfo &Info) {
-  // Trap errors.
+  // Unevaluated SFINAE context.
+  EnterExpressionEvaluationContext Unevaluated(S, Sema::Unevaluated);
   Sema::SFINAETrap Trap(S);
 
   Sema::ContextRAII SavedContext(S, Partial);
@@ -2145,7 +2146,11 @@
   //   argument list if the template arguments of the partial
   //   specialization can be deduced from the actual template argument
   //   list (14.8.2).
+
+  // Unevaluated SFINAE context.
+  EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
   SFINAETrap Trap(*this);
+
   SmallVector<DeducedTemplateArgument, 4> Deduced;
   Deduced.resize(Partial->getTemplateParameters()->size());
   if (TemplateDeductionResult Result
@@ -2226,8 +2231,8 @@
     return TDK_Success;
   }
 
-  // Substitution of the explicit template arguments into a function template
-  /// is a SFINAE context. Trap any errors that might occur.
+  // Unevaluated SFINAE context.
+  EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
   SFINAETrap Trap(*this);
 
   // C++ [temp.arg.explicit]p3:
@@ -2449,8 +2454,8 @@
   TemplateParameterList *TemplateParams
     = FunctionTemplate->getTemplateParameters();
 
-  // Template argument deduction for function templates in a SFINAE context.
-  // Trap any errors that might occur.
+  // Unevaluated SFINAE context.
+  EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
   SFINAETrap Trap(*this);
 
   // Enter a new template instantiation context while we instantiate the
@@ -3172,8 +3177,8 @@
     NumExplicitlySpecified = Deduced.size();
   }
 
-  // Template argument deduction for function templates in a SFINAE context.
-  // Trap any errors that might occur.
+  // Unevaluated SFINAE context.
+  EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
   SFINAETrap Trap(*this);
 
   Deduced.resize(TemplateParams->size());
@@ -3257,8 +3262,8 @@
     A = A.getUnqualifiedType();
   }
 
-  // Template argument deduction for function templates in a SFINAE context.
-  // Trap any errors that might occur.
+  // Unevaluated SFINAE context.
+  EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
   SFINAETrap Trap(*this);
 
   // C++ [temp.deduct.conv]p1: