From: Nick Lewycky Date: Fri, 28 Feb 2014 05:26:13 +0000 (+0000) Subject: Fix crash with enable_if on constructors. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=16487a6e0e4dde4ca1567e3b87ff3a7dec15b716;p=clang Fix crash with enable_if on constructors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202467 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index b95e289318..fb77ba616f 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -5646,7 +5646,8 @@ EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef Args, bool InitializationFailed = false; for (unsigned i = 0, e = Args.size(); i != e; ++i) { if (i == 0 && !MissingImplicitThis && isa(Function) && - !cast(Function)->isStatic()) { + !cast(Function)->isStatic() && + !isa(Function)) { CXXMethodDecl *Method = cast(Function); ExprResult R = PerformObjectArgumentInitialization(Args[0], /*Qualifier=*/0, diff --git a/test/SemaCXX/enable_if.cpp b/test/SemaCXX/enable_if.cpp index c1cdefeb4c..e9dc24254f 100644 --- a/test/SemaCXX/enable_if.cpp +++ b/test/SemaCXX/enable_if.cpp @@ -4,6 +4,10 @@ typedef int (*fp)(int); int surrogate(int); struct X { + X() = default; // expected-note{{candidate constructor not viable: requires 0 arguments, but 1 was provided}} + X(const X&) = default; // expected-note{{candidate constructor not viable: no known conversion from 'bool' to 'const X' for 1st argument}} + X(bool b) __attribute__((enable_if(b, "chosen when 'b' is true"))); // expected-note{{candidate disabled: chosen when 'b' is true}} + void f(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))); void f(int n) __attribute__((enable_if(n == 1, "chosen when 'n' is one"))); // expected-note{{member declaration nearly matches}} expected-note{{candidate disabled: chosen when 'n' is one}} @@ -26,6 +30,9 @@ void X::f(int n) __attribute__((enable_if(n == 2, "chosen when 'n' is two"))) / { } +X x1(true); +X x2(false); // expected-error{{no matching constructor for initialization of 'X'}} + __attribute__((deprecated)) constexpr int old() { return 0; } // expected-note2{{'old' has been explicitly marked deprecated here}} void deprec1(int i) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}} void deprec2(int i) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}}