]> granicus.if.org Git - clang/commitdiff
Fix crash with enable_if on constructors.
authorNick Lewycky <nicholas@mxc.ca>
Fri, 28 Feb 2014 05:26:13 +0000 (05:26 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Fri, 28 Feb 2014 05:26:13 +0000 (05:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202467 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
test/SemaCXX/enable_if.cpp

index b95e28931899d4b6c560e43fe25bd46f7fb028aa..fb77ba616f6e62b1498ac2ab7c1e1524ad3ab5c9 100644 (file)
@@ -5646,7 +5646,8 @@ EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef<Expr *> Args,
   bool InitializationFailed = false;
   for (unsigned i = 0, e = Args.size(); i != e; ++i) {
     if (i == 0 && !MissingImplicitThis && isa<CXXMethodDecl>(Function) &&
-        !cast<CXXMethodDecl>(Function)->isStatic()) {
+        !cast<CXXMethodDecl>(Function)->isStatic() &&
+        !isa<CXXConstructorDecl>(Function)) {
       CXXMethodDecl *Method = cast<CXXMethodDecl>(Function);
       ExprResult R =
         PerformObjectArgumentInitialization(Args[0], /*Qualifier=*/0,
index c1cdefeb4cefe5c126f10e48ad2662795bdc71db..e9dc24254f209b58b2e93d4d8c577780da846b32 100644 (file)
@@ -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}}