1 // Test for "contextually converted to bool"
2 // { dg-options "-std=c++0x" }
3
4 struct A
5 {
6 explicit operator bool();
7 };
8
9 void f (bool);
10
11 struct B
12 {
13 bool b;
14 };
15
16 struct C
17 {
18 operator int();
19 };
20
21 struct D
22 {
23 operator int();
24 };
25
main()26 int main()
27 {
28 A a; C c; D d;
29 // These contexts use an explicit bool conversion.
30 if (a) {}
31 for (; a; ) {}
32 do {} while (a);
33 while (a) {}
34 a ? 1 : 0;
35 a || true;
36 a && true;
37 !a;
38
39 a ? c : 1;
40 a ? c : d;
41
42 // These do not.
43 switch (a); // { dg-error "" }
44 bool b = a; // { dg-error "" }
45 // { dg-message "candidate" "candidate note" { target *-*-* } 44 }
46 f(a); // { dg-error "" }
47 B b2 = { a }; // { dg-error "" }
48 a + true; // { dg-message "" }
49 b ? a : true; // { dg-message "" }
50 a ? a : true; // { dg-message "" }
51 }
52