1 // RUN: %clang_cc1 -std=c++11 -verify %s 2 3 typedef int (*fp)(int); 4 int surrogate(int); 5 6 struct X { 7 X() = default; // expected-note{{candidate constructor not viable: requires 0 arguments, but 1 was provided}} 8 X(const X&) = default; // expected-note{{candidate constructor not viable: no known conversion from 'bool' to 'const X' for 1st argument}} 9 X(bool b) __attribute__((enable_if(b, "chosen when 'b' is true"))); // expected-note{{candidate disabled: chosen when 'b' is true}} 10 11 void f(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))); 12 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}} 13 14 static void s(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))); // expected-note2{{candidate disabled: chosen when 'n' is zero}} 15 16 void conflict(int n) __attribute__((enable_if(n+n == 10, "chosen when 'n' is five"))); // expected-note{{candidate function}} 17 void conflict(int n) __attribute__((enable_if(n*2 == 10, "chosen when 'n' is five"))); // expected-note{{candidate function}} 18 19 operator long() __attribute__((enable_if(true, "chosen on your platform"))); 20 operator int() __attribute__((enable_if(false, "chosen on other platform"))); 21 22 operator fp() __attribute__((enable_if(false, "never enabled"))) { return surrogate; } // expected-note{{conversion candidate of type 'int (*)(int)'}} // FIXME: the message is not displayed 23 }; 24 25 void X::f(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))) // expected-note{{member declaration nearly matches}} expected-note{{candidate disabled: chosen when 'n' is zero}} 26 { 27 } 28 29 void X::f(int n) __attribute__((enable_if(n == 2, "chosen when 'n' is two"))) // expected-error{{out-of-line definition of 'f' does not match any declaration in 'X'}} expected-note{{candidate disabled: chosen when 'n' is two}} 30 { 31 } 32 33 X x1(true); 34 X x2(false); // expected-error{{no matching constructor for initialization of 'X'}} 35 36 __attribute__((deprecated)) constexpr int old() { return 0; } // expected-note2{{'old' has been explicitly marked deprecated here}} 37 void deprec1(int i) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}} 38 void deprec2(int i) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}} 39 40 void overloaded(int); 41 void overloaded(long); 42 43 struct Nothing { }; 44 template<typename T> void typedep(T t) __attribute__((enable_if(t, ""))); // expected-note{{candidate disabled:}} expected-error{{value of type 'Nothing' is not contextually convertible to 'bool'}} 45 template<int N> void valuedep() __attribute__((enable_if(N == 1, ""))); 46 47 // FIXME: we skip potential constant expression evaluation on value dependent 48 // enable-if expressions 49 int not_constexpr(); 50 template<int N> void valuedep() __attribute__((enable_if(N == not_constexpr(), ""))); 51 52 template <typename T> void instantiationdep() __attribute__((enable_if(sizeof(sizeof(T)) != 0, ""))); 53 54 void test() { 55 X x; 56 x.f(0); 57 x.f(1); 58 x.f(2); // no error, suppressed by erroneous out-of-line definition 59 x.f(3); // expected-error{{no matching member function for call to 'f'}} 60 61 x.s(0); 62 x.s(1); // expected-error{{no matching member function for call to 's'}} 63 64 X::s(0); 65 X::s(1); // expected-error{{no matching member function for call to 's'}} 66 67 x.conflict(5); // expected-error{{call to member function 'conflict' is ambiguous}} 68 69 deprec2(0); 70 71 overloaded(x); 72 73 int i = x(1); // expected-error{{no matching function for call to object of type 'X'}} 74 75 Nothing n; 76 typedep(0); // expected-error{{no matching function for call to 'typedep'}} 77 typedep(1); 78 typedep(n); // expected-note{{in instantiation of function template specialization 'typedep<Nothing>' requested here}} 79 } 80