1 // RUN: %clang_cc1 -std=c++11 -verify %s
2 // RUN: %clang_cc1 -std=c++2a -verify %s
3 typedef int (*fp
)(int);
5 struct Incomplete
; // expected-note{{forward declaration of 'Incomplete'}} \
6 // expected-note {{forward declaration of 'Incomplete'}}
9 X() = default; // expected-note{{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
10 X(const X
&) = default; // expected-note{{candidate constructor not viable: no known conversion from 'bool' to 'const X' for 1st argument}}
11 X(bool b
) __attribute__((enable_if(b
, "chosen when 'b' is true"))); // expected-note{{candidate disabled: chosen when 'b' is true}}
13 void f(int n
) __attribute__((enable_if(n
== 0, "chosen when 'n' is zero")));
14 void f(int n
) __attribute__((enable_if(n
== 1, "chosen when 'n' is one"))); // expected-note{{member declaration nearly matches}} expected-note 2{{candidate disabled: chosen when 'n' is one}}
16 void g(int n
) __attribute__((enable_if(n
== 0, "chosen when 'n' is zero"))); // expected-note{{candidate disabled: chosen when 'n' is zero}}
18 void h(int n
, int m
= 0) __attribute__((enable_if(m
== 0, "chosen when 'm' is zero"))); // expected-note{{candidate disabled: chosen when 'm' is zero}}
20 static void s(int n
) __attribute__((enable_if(n
== 0, "chosen when 'n' is zero"))); // expected-note2{{candidate disabled: chosen when 'n' is zero}}
22 void conflict(int n
) __attribute__((enable_if(n
+n
== 10, "chosen when 'n' is five"))); // expected-note{{candidate function}}
23 void conflict(int n
) __attribute__((enable_if(n
*2 == 10, "chosen when 'n' is five"))); // expected-note{{candidate function}}
25 void hidden_by_argument_conversion(Incomplete n
, int m
= 0) __attribute__((enable_if(m
== 10, "chosen when 'm' is ten")));
26 Incomplete
hidden_by_incomplete_return_value(int n
= 0) __attribute__((enable_if(n
== 10, "chosen when 'n' is ten"))); // expected-note{{'hidden_by_incomplete_return_value' declared here}}
28 operator long() __attribute__((enable_if(true, "chosen on your platform")));
29 operator int() __attribute__((enable_if(false, "chosen on other platform")));
31 operator fp() __attribute__((enable_if(false, "never enabled"))) { return surrogate
; } // expected-note{{conversion candidate of type 'int (*)(int)'}} // FIXME: the message is not displayed
34 void X::f(int n
) __attribute__((enable_if(n
== 0, "chosen when 'n' is zero"))) // expected-note{{member declaration nearly matches}} expected-note 2{{candidate disabled: chosen when 'n' is zero}}
38 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'}}
43 X
x2(false); // expected-error{{no matching constructor for initialization of 'X'}}
45 __attribute__((deprecated
)) constexpr int old() { return 0; } // expected-note2{{'old' has been explicitly marked deprecated here}}
46 void deprec1(int i
) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}}
47 void deprec2(int i
) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}}
50 void overloaded(long);
53 constexpr Int(int i
) : i(i
) { }
54 constexpr operator int() const { return i
; }
58 void default_argument(int n
, int m
= 0) __attribute__((enable_if(m
== 0, "chosen when 'm' is zero"))); // expected-note{{candidate disabled: chosen when 'm' is zero}}
59 void default_argument_promotion(int n
, int m
= Int(0)) __attribute__((enable_if(m
== 0, "chosen when 'm' is zero"))); // expected-note{{candidate disabled: chosen when 'm' is zero}}
62 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'}}
63 template<int N
> void valuedep() __attribute__((enable_if(N
== 1, "")));
65 // FIXME: we skip potential constant expression evaluation on value dependent
66 // enable-if expressions
68 template<int N
> void valuedep() __attribute__((enable_if(N
== not_constexpr(), "")));
70 template <typename T
> void instantiationdep() __attribute__((enable_if(sizeof(sizeof(T
)) != 0, "")));
76 x
.f(2); // expected-error{{no matching member function for call to 'f'}}
77 x
.f(3); // expected-error{{no matching member function for call to 'f'}}
80 x
.g(1); // expected-error{{no matching member function for call to 'g'}}
83 x
.h(1, 2); // expected-error{{no matching member function for call to 'h'}}
86 x
.s(1); // expected-error{{no matching member function for call to 's'}}
89 X::s(1); // expected-error{{no matching member function for call to 's'}}
91 x
.conflict(5); // expected-error{{call to member function 'conflict' is ambiguous}}
93 x
.hidden_by_argument_conversion(10); // expected-error{{argument type 'Incomplete' is incomplete}}
94 x
.hidden_by_incomplete_return_value(10); // expected-error{{calling 'hidden_by_incomplete_return_value' with incomplete return type 'Incomplete'}}
101 default_argument(1, 2); // expected-error{{no matching function for call to 'default_argument'}}
103 default_argument_promotion(0);
104 default_argument_promotion(1, 2); // expected-error{{no matching function for call to 'default_argument_promotion'}}
106 int i
= x(1); // expected-error{{no matching function for call to object of type 'X'}}
109 typedep(0); // expected-error{{no matching function for call to 'typedep'}}
111 typedep(n
); // expected-note{{in instantiation of function template specialization 'typedep<Nothing>' requested here}}
114 template <typename T
> class C
{
115 void f() __attribute__((enable_if(T::expr
== 0, ""))) {}
119 int fn3(bool b
) __attribute__((enable_if(b
, ""))); // FIXME: This test should net 0 error messages.
120 template <class T
> void test3() {
121 fn3(sizeof(T
) == 1); // expected-error{{no matching function for call to 'fn3'}} expected-note@-2{{candidate disabled}}
124 template <typename T
>
126 T
h(int n
, int m
= 0) __attribute__((enable_if(m
== 0, "chosen when 'm' is zero"))); // expected-note{{candidate disabled: chosen when 'm' is zero}}
133 int t1
= y
.h(1, 2); // expected-error{{no matching member function for call to 'h'}}
136 // FIXME: issue an error (without instantiation) because ::h(T()) is not
137 // convertible to bool, because return types aren't overloadable.
139 template <typename T
> void outer() {
140 void local_function() __attribute__((enable_if(::h(T()), "")));
141 local_function(); // expected-error{{no matching function for call to 'local_function'}} expected-note@-1{{candidate disabled}}
149 int fn1(const Integer
&) __attribute__((enable_if(true, "")));
150 template <class T
> void test1() {
151 int &expr
= T::expr();
155 int fn2(const Integer
&) __attribute__((enable_if(false, ""))); // expected-note{{candidate disabled}}
156 template <class T
> void test2() {
157 int &expr
= T::expr();
158 fn2(expr
); // expected-error{{no matching function for call to 'fn2'}}
161 int fn3(bool b
) __attribute__((enable_if(b
, ""))); // FIXME: This test should net 0 error messages.
162 template <class T
> void test3() {
163 fn3(sizeof(T
) == 1); // expected-error{{no matching function for call to 'fn3'}} expected-note@-2{{candidate disabled}}
168 int ovlFoo(int m
) __attribute__((enable_if(m
> 0, "")));
172 // Assignment gives us a different code path than declarations, and `&foo`
173 // gives us a different code path than `foo`
174 int (*p
)(int) = ovlFoo
;
175 int (*p2
)(int) = &ovlFoo
;
181 int ovlBar(int) __attribute__((enable_if(true, "")));
182 int ovlBar(int m
) __attribute__((enable_if(false, "")));
184 int (*p
)(int) = ovlBar
;
185 int (*p2
)(int) = &ovlBar
;
191 int ovlConflict(int m
) __attribute__((enable_if(true, "")));
192 int ovlConflict(int m
) __attribute__((enable_if(1, "")));
194 int (*p
)(int) = ovlConflict
; // expected-error{{address of overloaded function 'ovlConflict' is ambiguous}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
195 int (*p2
)(int) = &ovlConflict
; // expected-error{{address of overloaded function 'ovlConflict' is ambiguous}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
197 a
= ovlConflict
; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function type>'}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
198 a
= &ovlConflict
; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function type>'}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
201 template <typename T
>
202 T
templated(T m
) __attribute__((enable_if(true, ""))) { return T(); }
203 template <typename T
>
204 T
templated(T m
) __attribute__((enable_if(false, ""))) { return T(); }
206 int (*p
)(int) = templated
<int>;
207 int (*p2
)(int) = &templated
<int>;
213 template <typename T
>
214 T
templatedBar(T m
) __attribute__((enable_if(m
> 0, ""))) { return T(); }
216 int (*p
)(int) = templatedBar
<int>; // expected-error{{address of overloaded function 'templatedBar' does not match required type 'int (int)'}} expected-note@214{{candidate function made ineligible by enable_if}}
217 int (*p2
)(int) = &templatedBar
<int>; // expected-error{{address of overloaded function 'templatedBar' does not match required type 'int (int)'}} expected-note@214{{candidate function made ineligible by enable_if}}
219 a
= templatedBar
<int>; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function type>'}} expected-note@214{{candidate function made ineligible by enable_if}}
220 a
= &templatedBar
<int>; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function type>'}} expected-note@214{{candidate function made ineligible by enable_if}}
223 template <typename T
>
224 T
templatedConflict(T m
) __attribute__((enable_if(false, ""))) { return T(); }
225 template <typename T
>
226 T
templatedConflict(T m
) __attribute__((enable_if(true, ""))) { return T(); }
227 template <typename T
>
228 T
templatedConflict(T m
) __attribute__((enable_if(1, ""))) { return T(); }
230 int (*p
)(int) = templatedConflict
<int>; // expected-error{{address of overloaded function 'templatedConflict' is ambiguous}} expected-note@224{{candidate function made ineligible by enable_if}} expected-note@226{{candidate function}} expected-note@228{{candidate function}}
231 int (*p0
)(int) = &templatedConflict
<int>; // expected-error{{address of overloaded function 'templatedConflict' is ambiguous}} expected-note@224{{candidate function made ineligible by enable_if}} expected-note@226{{candidate function}} expected-note@228{{candidate function}}
233 a
= templatedConflict
<int>; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function type>'}} expected-note@226{{candidate function}} expected-note@228{{candidate function}}
234 a
= &templatedConflict
<int>; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function type>'}} expected-note@226{{candidate function}} expected-note@228{{candidate function}}
237 int ovlNoCandidate(int m
) __attribute__((enable_if(false, "")));
238 int ovlNoCandidate(int m
) __attribute__((enable_if(0, "")));
240 int (*p
)(int) = ovlNoCandidate
; // expected-error{{address of overloaded function 'ovlNoCandidate' does not match required type}} expected-note@237{{made ineligible by enable_if}} expected-note@238{{made ineligible by enable_if}}
241 int (*p2
)(int) = &ovlNoCandidate
; // expected-error{{address of overloaded function 'ovlNoCandidate' does not match required type}} expected-note@237{{made ineligible by enable_if}} expected-note@238{{made ineligible by enable_if}}
243 a
= ovlNoCandidate
; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function type>'}} expected-note@237{{made ineligible by enable_if}} expected-note@238{{made ineligible by enable_if}}
244 a
= &ovlNoCandidate
; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function type>'}} expected-note@237{{made ineligible by enable_if}} expected-note@238{{made ineligible by enable_if}}
247 int noOvlNoCandidate(int m
) __attribute__((enable_if(false, "")));
249 int (*p
)(int) = noOvlNoCandidate
; // expected-error{{cannot take address of function 'noOvlNoCandidate' because it has one or more non-tautological enable_if conditions}}
250 int (*p2
)(int) = &noOvlNoCandidate
; // expected-error{{cannot take address of function 'noOvlNoCandidate' because it has one or more non-tautological enable_if conditions}}
252 a
= noOvlNoCandidate
; // expected-error{{cannot take address of function 'noOvlNoCandidate' because it has one or more non-tautological enable_if conditions}}
253 a
= &noOvlNoCandidate
; // expected-error{{cannot take address of function 'noOvlNoCandidate' because it has one or more non-tautological enable_if conditions}}
258 using VoidFnTy
= void (*)();
260 void foo(void *c
) __attribute__((enable_if(0, "")));
261 void foo(int *c
) __attribute__((enable_if(c
, "")));
262 void foo(char *c
) __attribute__((enable_if(1, "")));
265 auto A
= reinterpret_cast<VoidFnTy
>(foo
);
266 auto AAmp
= reinterpret_cast<VoidFnTy
>(&foo
);
268 using VoidFooTy
= void (*)(void *);
269 auto B
= reinterpret_cast<VoidFooTy
>(foo
);
270 auto BAmp
= reinterpret_cast<VoidFooTy
>(&foo
);
272 using IntFooTy
= void (*)(int *);
273 auto C
= reinterpret_cast<IntFooTy
>(foo
);
274 auto CAmp
= reinterpret_cast<IntFooTy
>(&foo
);
276 using CharFooTy
= void (*)(void *);
277 auto D
= reinterpret_cast<CharFooTy
>(foo
);
278 auto DAmp
= reinterpret_cast<CharFooTy
>(&foo
);
281 void testItCStyle() {
282 auto A
= (VoidFnTy
)foo
;
283 auto AAmp
= (VoidFnTy
)&foo
;
285 using VoidFooTy
= void (*)(void *);
286 auto B
= (VoidFooTy
)foo
;
287 auto BAmp
= (VoidFooTy
)&foo
;
289 using IntFooTy
= void (*)(int *);
290 auto C
= (IntFooTy
)foo
;
291 auto CAmp
= (IntFooTy
)&foo
;
293 using CharFooTy
= void (*)(void *);
294 auto D
= (CharFooTy
)foo
;
295 auto DAmp
= (CharFooTy
)&foo
;
299 namespace casting_templates
{
300 template <typename T
> void foo(T
) {} // expected-note 4 {{candidate function}}
302 void foo(int *c
) __attribute__((enable_if(c
, ""))); //expected-note 4 {{candidate function}}
303 void foo(char *c
) __attribute__((enable_if(c
, ""))); //expected-note 4 {{candidate function}}
306 using IntFooTy
= void (*)(int *);
307 auto A
= reinterpret_cast<IntFooTy
>(foo
); // expected-error{{reinterpret_cast cannot resolve overloaded function 'foo' to type}}
308 auto ARef
= reinterpret_cast<IntFooTy
>(&foo
); // expected-error{{reinterpret_cast cannot resolve overloaded function 'foo' to type}}
309 auto AExplicit
= reinterpret_cast<IntFooTy
>(foo
<int*>);
311 using CharFooTy
= void (*)(char *);
312 auto B
= reinterpret_cast<CharFooTy
>(foo
); // expected-error{{reinterpret_cast cannot resolve overloaded function 'foo' to type}}
313 auto BRef
= reinterpret_cast<CharFooTy
>(&foo
); // expected-error{{reinterpret_cast cannot resolve overloaded function 'foo' to type}}
314 auto BExplicit
= reinterpret_cast<CharFooTy
>(foo
<char*>);
317 void testItCStyle() {
318 // constexpr is usable here because all of these should become static_casts.
319 using IntFooTy
= void (*)(int *);
320 constexpr auto A
= (IntFooTy
)foo
;
321 constexpr auto ARef
= (IntFooTy
)&foo
;
322 constexpr auto AExplicit
= (IntFooTy
)foo
<int*>;
324 using CharFooTy
= void (*)(char *);
325 constexpr auto B
= (CharFooTy
)foo
;
326 constexpr auto BRef
= (CharFooTy
)&foo
;
327 constexpr auto BExplicit
= (CharFooTy
)foo
<char*>;
329 static_assert(A
== ARef
&& ARef
== AExplicit
, "");
330 static_assert(B
== BRef
&& BRef
== BExplicit
, "");
334 namespace multiple_matches
{
335 using NoMatchTy
= void (*)();
337 void foo(float *c
); //expected-note 4 {{candidate function}}
338 void foo(int *c
) __attribute__((enable_if(1, ""))); //expected-note 4 {{candidate function}}
339 void foo(char *c
) __attribute__((enable_if(1, ""))); //expected-note 4 {{candidate function}}
342 auto A
= reinterpret_cast<NoMatchTy
>(foo
); // expected-error{{reinterpret_cast cannot resolve overloaded function 'foo' to type}}
343 auto ARef
= reinterpret_cast<NoMatchTy
>(&foo
); // expected-error{{reinterpret_cast cannot resolve overloaded function 'foo' to type}}
345 auto C
= (NoMatchTy
)foo
; // expected-error{{address of overloaded function 'foo' does not match required type 'void ()'}}
346 auto CRef
= (NoMatchTy
)&foo
; // expected-error{{address of overloaded function 'foo' does not match required type 'void ()'}}
351 // (slightly reduced) code that motivated the bug...
353 void Function(int num
)
354 __attribute__((enable_if(num
!= 0, "")));
355 void Function(int num
, int a0
)
356 __attribute__((enable_if(num
!= 1, "")));
359 using ns::Function
; // expected-note 3{{declared here}}
361 Functioon(0); // expected-error{{use of undeclared identifier}} expected-error{{too few arguments}}
362 Functioon(0, 1); // expected-error{{use of undeclared identifier}}
363 Functioon(0, 1, 2); // expected-error{{use of undeclared identifier}}
367 void regularEnableIf(int a
) __attribute__((enable_if(a
, ""))); // expected-note 3{{declared here}} expected-note 3{{candidate function not viable}}
368 void runRegularEnableIf() {
369 regularEnableIf(0, 2); // expected-error{{no matching function}}
370 regularEnableIf(1, 2); // expected-error{{no matching function}}
371 regularEnableIf(); // expected-error{{no matching function}}
373 // Test without getting overload resolution involved
374 ::PR27122::regularEnableIf(0, 2); // expected-error{{too many arguments}}
375 ::PR27122::regularEnableIf(1, 2); // expected-error{{too many arguments}}
376 ::PR27122::regularEnableIf(); // expected-error{{too few arguments}}
380 void bar(int i
) __attribute__((enable_if(i
, ""))); // expected-note 2{{declared here}}
385 f
.bar(); // expected-error{{too few arguments}}
386 f
.bar(1, 2); // expected-error{{too many arguments}}
390 // Ideally, we should be able to handle value-dependent expressions sanely.
391 // Sadly, that isn't the case at the moment.
392 namespace dependent
{
393 int error(int N
) __attribute__((enable_if(N
, ""))); // expected-note{{candidate disabled}}
394 int error(int N
) __attribute__((enable_if(!N
, ""))); // expected-note{{candidate disabled}}
395 template <int N
> int callUnavailable() {
396 return error(N
); // expected-error{{no matching function for call to 'error'}}
399 constexpr int noError(int N
) __attribute__((enable_if(N
, ""))) { return -1; }
400 constexpr int noError(int N
) __attribute__((enable_if(!N
, ""))) { return -1; }
401 constexpr int noError(int N
) { return 0; }
404 constexpr int callNoError() { return noError(N
); }
405 static_assert(callNoError
<0>() == 0, "");
406 static_assert(callNoError
<1>() == 0, "");
408 template <int N
> constexpr int templated() __attribute__((enable_if(N
, ""))) {
412 constexpr int A
= templated
<0>(); // expected-error{{no matching function for call to 'templated'}} expected-note@-4{{candidate disabled}}
413 static_assert(templated
<1>() == 1, "");
415 template <int N
> constexpr int callTemplated() { return templated
<N
>(); }
417 constexpr int B
= 10 + // expected-error {{initialized by a constant expression}}
418 callTemplated
<0>(); // expected-error@-3{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note@-10{{candidate disabled}}
419 static_assert(callTemplated
<1>() == 1, "");
423 void foo(int a
, int b
= 0, ...) __attribute__((enable_if(a
&& b
, ""))); // expected-note 6{{disabled}}
430 foo(1, 0); // expected-error{{no matching}}
431 foo(1, 0, 2); // expected-error{{no matching}}
432 foo(1, 0, 2, 3); // expected-error{{no matching}}
439 foo(1, 0); // expected-error{{no matching}}
440 foo(1, 0, m
); // expected-error{{no matching}}
441 foo(1, 0, m
, 3); // expected-error{{no matching}}
445 // Tests that we emit errors at the point of the method call, rather than the
446 // beginning of the expression that happens to be a member call.
447 namespace member_loc
{
448 struct Foo
{ void bar() __attribute__((enable_if(0, ""))); }; // expected-note{{disabled}}
451 .bar(); // expected-error{{no matching member function}}
455 // Prior bug: we wouldn't properly convert conditions to bools when
456 // instantiating templates in some cases.
457 namespace template_instantiation
{
458 template <typename T
>
460 void bar(int a
) __attribute__((enable_if(a
, ""))); // expected-note{{disabled}}
464 Foo
<double>().bar(0); // expected-error{{no matching}}
465 Foo
<double>().bar(1);
469 namespace instantiate_constexpr_in_enable_if
{
470 template<typename T
> struct X
{
471 static constexpr bool ok() { return true; }
472 void f() __attribute__((enable_if(ok(), "")));
474 void g() { X
<int>().f(); }
478 int foo(int a
) __attribute__((enable_if(a
, "")));
479 int runFn(int (&)(int));
483 int (&bar
)(int) = foo
; // expected-error{{cannot take address of function 'foo'}}
484 int baz
= runFn(foo
); // expected-error{{cannot take address of function 'foo'}}
488 int (&bar
)(int) = (foo
); // expected-error{{cannot take address of function 'foo'}}
489 int baz
= runFn((foo
)); // expected-error{{cannot take address of function 'foo'}}
493 int (&bar
)(int) = static_cast<int (&)(int)>(foo
); // expected-error{{cannot take address of function 'foo'}}
494 int baz
= runFn(static_cast<int (&)(int)>(foo
)); // expected-error{{cannot take address of function 'foo'}}
498 int (&bar
)(int) = static_cast<int (&)(int)>((foo
)); // expected-error{{cannot take address of function 'foo'}}
499 int baz
= runFn(static_cast<int (&)(int)>((foo
))); // expected-error{{cannot take address of function 'foo'}}
505 template <typename T
, typename U
>
508 template <typename T
> struct is_same
<T
, T
> {
512 void foo(int a
) __attribute__((enable_if(a
, "")));
513 void foo(float a
) __attribute__((enable_if(1, "")));
515 static_assert(is_same
<__typeof__(foo
)*, decltype(&foo
)>::value
, "");
518 namespace InConstantContext
{
519 void foo(const char *s
) __attribute__((enable_if(((void)__builtin_constant_p(*s
), true), "trap"))) {}
522 InConstantContext::foo("abc");
524 } // namespace InConstantContext
526 namespace StringLiteralDetector
{
527 void need_string_literal(const char *p
) __attribute__((enable_if(__builtin_constant_p(p
), "argument is not a string literal"))); // expected-note 2{{not a string literal}}
528 void test(const char *unknown
) {
529 need_string_literal("foo");
530 need_string_literal(unknown
); // expected-error {{no matching function}}
531 constexpr char str
[] = "bar";
532 need_string_literal(str
); // expected-error {{no matching function}}
536 namespace IgnoreUnusedArgSideEffects
{
538 void f(A a
, bool b
) __attribute__((enable_if(b
, ""))); // expected-note 2-3{{disabled}}
541 f(A(), false); // expected-error {{no matching function}}
543 f((n
= 1, A()), true);
544 f(A(), (n
= 1, true)); // expected-error {{no matching function}}
548 #if __cplusplus > 201702L
549 struct B
{ constexpr ~B() {} bool b
; };
550 void g(B b
) __attribute__((enable_if(b
.b
, ""))); // expected-note {{disabled}}
553 g(B
{false}); // expected-error {{no matching function}}
555 f(A(), B
{false}.b
); // expected-error {{no matching function}}
558 // First condition is non-constant due to non-constexpr destructor of A.
559 int &h() __attribute__((enable_if((A(), true), "")));
560 float &h() __attribute__((enable_if((B(), true), "")));
565 namespace DefaultArgs
{
566 void f(int n
= __builtin_LINE()) __attribute__((enable_if(n
== 12345, "only callable on line 12345"))); // expected-note {{only callable on line 12345}}
567 void g() { f(); } // expected-error {{no matching function}}
571 template<typename T
> void x(int n
= T()) __attribute__((enable_if(n
== 0, ""))) {} // expected-note {{candidate}}
572 void y() { x
<int>(); }
573 struct Z
{ constexpr operator int() const { return 1; } };
574 void z() { x
<Z
>(); } // expected-error {{no matching function}}