OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [warn/] [Wparentheses-22.C] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
// { dg-do compile }
2
// { dg-options "-Wparentheses" }
3
 
4
// Warnings for assignments used as truth-values when using classes.
5
// Like Wparentheses-1.C, but with a class.
6
 
7
int foo (int);
8
 
9
class C
10
{
11
 public:
12
  C()
13
    : b(0)
14
  { }
15
 
16
  // Use default assignment constructor.
17
 
18
  // Provide conversion to bool so that an instance of this class will
19
  // work as a condition.
20
  operator bool() const
21
  { return b != 0; }
22
 
23
 private:
24
  int b;
25
};
26
 
27
C a, b, c;
28
bool d;
29
 
30
void
31
bar (void)
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
bool
90
bar1 (void)
91
{
92
  return a = b; // { dg-warning "assignment" "correct warning" }
93
}
94
 
95
bool
96
bar2 (void)
97
{
98
  return (a = b);
99
}
100
 
101
bool
102
bar3 (void)
103
{
104
  return a = a; // { dg-warning "assignment" "correct warning" }
105
}
106
 
107
bool
108
bar4 (void)
109
{
110
  return (a = a);
111
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.