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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@287187
91177308-0d34-0410-b5e6-
96231b3b80d8
return;
Cond = Result.getAs<Expr>();
}
- if (A->getCond()->isTypeDependent() && !Cond->isTypeDependent()) {
+ if (!Cond->isTypeDependent()) {
ExprResult Converted = S.PerformContextuallyConvertToBool(Cond);
if (Converted.isInvalid())
return;
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;
.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);
+}
+}