r287187 - [Sema] Fix a bug in enable_if condition instantiation.
George Burgess IV via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 16 17:33:54 PST 2016
Author: gbiv
Date: Wed Nov 16 19:33:54 2016
New Revision: 287187
URL: http://llvm.org/viewvc/llvm-project?rev=287187&view=rev
Log:
[Sema] Fix a bug in enable_if condition instantiation.
During template instantiation, we currently fall back to just calling
Sema::SubstExpr for enable_if attributes that aren't value-dependent or
type-dependent. Since Sema::SubstExpr strips off any implicit casts
we've added to an expression, it's possible that this behavior will
leave us with an enable_if condition that's just a DeclRefExpr.
Conditions like that deeply confuse Sema::CheckEnableIf.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaCXX/enable_if.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=287187&r1=287186&r2=287187&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Nov 16 19:33:54 2016
@@ -179,7 +179,7 @@ static void instantiateDependentEnableIf
return;
Cond = Result.getAs<Expr>();
}
- if (A->getCond()->isTypeDependent() && !Cond->isTypeDependent()) {
+ if (!Cond->isTypeDependent()) {
ExprResult Converted = S.PerformContextuallyConvertToBool(Cond);
if (Converted.isInvalid())
return;
@@ -332,8 +332,7 @@ void Sema::InstantiateAttrs(const MultiL
continue;
}
- const EnableIfAttr *EnableIf = dyn_cast<EnableIfAttr>(TmplAttr);
- if (EnableIf && EnableIf->getCond()->isValueDependent()) {
+ if (const auto *EnableIf = dyn_cast<EnableIfAttr>(TmplAttr)) {
instantiateDependentEnableIfAttr(*this, TemplateArgs, EnableIf, Tmpl,
New);
continue;
Modified: cfe/trunk/test/SemaCXX/enable_if.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enable_if.cpp?rev=287187&r1=287186&r2=287187&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/enable_if.cpp (original)
+++ cfe/trunk/test/SemaCXX/enable_if.cpp Wed Nov 16 19:33:54 2016
@@ -450,3 +450,17 @@ namespace member_loc {
.bar(); // expected-error{{no matching member function}}
}
}
+
+// Prior bug: we wouldn't properly convert conditions to bools when
+// instantiating templates in some cases.
+namespace template_instantiation {
+template <typename T>
+struct Foo {
+ void bar(int a) __attribute__((enable_if(a, ""))); // expected-note{{disabled}}
+};
+
+void runFoo() {
+ Foo<double>().bar(0); // expected-error{{no matching}}
+ Foo<double>().bar(1);
+}
+}
More information about the cfe-commits
mailing list