Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wparentheses-31.C

raw
1 /* Test that -Wparentheses warns for struct/class assignments,
2 except for explicit calls to operator= (). */
3 /* PR c++/25689 */
4 /* { dg-options "-Wparentheses" } */
5
6 struct A
7 {
8 A& operator= (int);
9 A operator= (double);
10 operator bool ();
11 };
12
13 struct B
14 {
15 bool x;
16 B& operator= (int);
17 B operator= (double);
18 operator bool ();
19 };
20
21 struct C
22 {
23 C& operator= (int);
24 virtual C operator= (double);
25 operator bool ();
26 };
27
28 /* Test empty class */
29 void f1 (A a1, A a2)
30 {
31 if (a1 = 0); /* { dg-warning "suggest parentheses" } */
32 if (a1 = 0.); /* { dg-warning "suggest parentheses" } */
33 if (a1.operator= (0));
34 if (a1.operator= (a2));
35
36 /* Ideally, we'd warn for empty classes using trivial operator= (below),
37 but we don't do so yet as it is a non-trivial COMPOUND_EXPR. */
38 if (a1 = a2); /* { dg-warning "suggest parentheses" "" { xfail *-*-* } } */
39 }
40
41 /* Test non-empty class */
42 void f2 (B b1, B b2)
43 {
44 if (b1 = 0); /* { dg-warning "suggest parentheses" } */
45 if (b1 = 0.); /* { dg-warning "suggest parentheses" } */
46 if (b1 = b2); /* { dg-warning "suggest parentheses" } */
47 if (b1.operator= (0));
48 if (b1.operator= (b2));
49 }
50
51 /* Test class with vtable */
52 void f3 (C c1, C c2)
53 {
54 if (c1 = 0); /* { dg-warning "suggest parentheses" } */
55 if (c1 = 0.); /* { dg-warning "suggest parentheses" } */
56 if (c1 = c2); /* { dg-warning "suggest parentheses" } */
57 if (c1.operator= (0));
58 if (c1.operator= (c2));
59 }