From e8f10cc0b9a9f6d30a25da68de700c2bac745b5c Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Wed, 11 May 2016 01:38:27 +0000 Subject: [Sema] Fix value-dependent enable_if bug. This patch fixes a bug where we would assume all value-dependent enable_if conditions give successful results. Instead, we consider value-dependent enable_if conditions to always fail. While this isn't ideal, this is the best we can realistically do without changing both enable_if's semantics and large parts of Sema (specifically, all of the parts that don't expect type dependence to come out of nowhere, and that may interact with overload resolution). Differential Revision: http://reviews.llvm.org/D20130 llvm-svn: 269154 --- clang/lib/Sema/SemaOverload.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'clang/lib/Sema') diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 36e79f7bb48..481c245bdd8 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -5984,7 +5984,6 @@ EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef Args, SFINAETrap Trap(*this); SmallVector ConvertedArgs; bool InitializationFailed = false; - bool ContainsValueDependentExpr = false; // Convert the arguments. for (unsigned I = 0, E = Args.size(); I != E; ++I) { @@ -6006,7 +6005,6 @@ EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef Args, break; } - ContainsValueDependentExpr |= R.get()->isValueDependent(); ConvertedArgs.push_back(R.get()); } @@ -6027,7 +6025,6 @@ EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef Args, InitializationFailed = true; break; } - ContainsValueDependentExpr |= R.get()->isValueDependent(); ConvertedArgs.push_back(R.get()); } @@ -6037,18 +6034,14 @@ EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef Args, for (auto *EIA : EnableIfAttrs) { APValue Result; - if (EIA->getCond()->isValueDependent()) { - // Don't even try now, we'll examine it after instantiation. - continue; - } - + // FIXME: This doesn't consider value-dependent cases, because doing so is + // very difficult. Ideally, we should handle them more gracefully. if (!EIA->getCond()->EvaluateWithSubstitution( - Result, Context, Function, llvm::makeArrayRef(ConvertedArgs))) { - if (!ContainsValueDependentExpr) - return EIA; - } else if (!Result.isInt() || !Result.getInt().getBoolValue()) { + Result, Context, Function, llvm::makeArrayRef(ConvertedArgs))) + return EIA; + + if (!Result.isInt() || !Result.getInt().getBoolValue()) return EIA; - } } return nullptr; } -- cgit v1.2.3