]> gcc.gnu.org Git - gcc.git/blob - gcc/testsuite/g++.dg/warn/Wparentheses-23.C
c-common.c (c_common_truthvalue_conversion): When warning about using an assignment...
[gcc.git] / gcc / testsuite / g++.dg / warn / Wparentheses-23.C
1 // { dg-do compile }
2 // { dg-options "-Wparentheses" }
3
4 // Template version of Wparentheses-22.C.
5
6 int foo (int);
7
8 class C
9 {
10 public:
11 C()
12 : b(0)
13 { }
14
15 // Use default assignment constructor.
16
17 // Provide conversion to bool so that an instance of this class will
18 // work as a condition.
19 operator bool() const
20 { return b != 0; }
21
22 private:
23 int b;
24 };
25
26 C a, b, c;
27 bool d;
28
29 template<class T>
30 void
31 bar (T)
32 {
33 if (a = b) // { dg-warning "assignment" "correct warning" }
34 foo (0);
35 if ((a = b))
36 foo (1);
37 if (a = a) // { dg-warning "assignment" "correct warning" }
38 foo (2);
39 if ((a = a))
40 foo (3);
41 if (b = c) // { dg-warning "assignment" "correct warning" }
42 foo (4);
43 else
44 foo (5);
45 if ((b = c))
46 foo (6);
47 else
48 foo (7);
49 if (b = b) // { dg-warning "assignment" "correct warning" }
50 foo (8);
51 else
52 foo (9);
53 if ((b = b))
54 foo (10);
55 else
56 foo (11);
57 while (c = b) // { dg-warning "assignment" "correct warning" }
58 foo (12);
59 while ((c = b))
60 foo (13);
61 while (c = c) // { dg-warning "assignment" "correct warning" }
62 foo (14);
63 while ((c = c))
64 foo (15);
65 do foo (16); while (a = b); // { dg-warning "assignment" "correct warning" }
66 do foo (17); while ((a = b));
67 do foo (18); while (a = a); // { dg-warning "assignment" "correct warning" }
68 do foo (19); while ((a = a));
69 for (;c = b;) // { dg-warning "assignment" "correct warning" }
70 foo (20);
71 for (;(c = b);)
72 foo (21);
73 for (;c = c;) // { dg-warning "assignment" "correct warning" }
74 foo (22);
75 for (;(c = c);)
76 foo (23);
77 d = a = b; // { dg-warning "assignment" "correct warning" }
78 foo (24);
79 d = (a = b);
80 foo (25);
81 d = a = a; // { dg-warning "assignment" "correct warning" }
82 foo (26);
83 d = (a = a);
84 foo (27);
85 if (C(a))
86 foo (28);
87 }
88
89 template<class T>
90 bool
91 bar1 (T)
92 {
93 return a = b; // { dg-warning "assignment" "correct warning" }
94 }
95
96 template<class T>
97 bool
98 bar2 (T)
99 {
100 return (a = b);
101 }
102
103 template<class T>
104 bool
105 bar3 (T)
106 {
107 return a = a; // { dg-warning "assignment" "correct warning" }
108 }
109
110 template<class T>
111 bool
112 bar4 (T)
113 {
114 return (a = a);
115 }
116
117 template void bar<int> (int); // { dg-warning "instantiated" }
118 template bool bar1<int> (int); // { dg-warning "instantiated" }
119 template bool bar2<int> (int);
120 template bool bar3<int> (int); // { dg-warning "instantiated" }
121 template bool bar4<int> (int);
This page took 0.04206 seconds and 5 git commands to generate.