| 1 |
// { dg-additional-options -Wparentheses } |
| 2 |
|
| 3 |
// Most Vexing Parse warnings |
| 4 |
// in C++ anythig that syntactically looks like a decl IS a decl, this |
| 5 |
// can lead to confused users, but worse silent unexpectedly unsafe |
| 6 |
// code generation. |
| 7 |
|
| 8 |
int (a); // { dg-warning "" } |
| 9 |
int (*b); // { dg-warning "" } |
| 10 |
extern int (&c); // { dg-warning "" } |
| 11 |
|
| 12 |
int h1 = 0, h2 = 0; |
| 13 |
struct H { H(...);}; |
| 14 |
|
| 15 |
namespace fns |
| 16 |
{ |
| 17 |
int (*a) (); |
| 18 |
int (b) (); |
| 19 |
int (*c ()) (); |
| 20 |
int (d1 ()); // { dg-warning "" } |
| 21 |
int (d2 // { dg-warning "" } |
| 22 |
()); |
| 23 |
int (e) (int); |
| 24 |
int g (int (a)); // No warning because ... |
| 25 |
H h (int (h1), int (h2), 3); // ... not a function decl. |
| 26 |
} |
| 27 |
|
| 28 |
namespace arys |
| 29 |
{ |
| 30 |
int (*a)[1]; |
| 31 |
int (b)[1]; |
| 32 |
int (*c[1])[1]; |
| 33 |
int (d1[1]); // { dg-warning "" } |
| 34 |
int (d2 |
| 35 |
[1]); |
| 36 |
int (e[1])[1]; |
| 37 |
} |
| 38 |
|
| 39 |
namespace complex |
| 40 |
{ |
| 41 |
int (*a())[1]; |
| 42 |
int (*b[1])(); |
| 43 |
int ((*c1())[1]); // { dg-warning "" } |
| 44 |
int ((*c2()) |
| 45 |
[1]); |
| 46 |
int ((*d1[1])()); // { dg-warning "" } |
| 47 |
int ((*d2[1]) // { dg-warning "" } |
| 48 |
()); |
| 49 |
} |
| 50 |
|
| 51 |
namespace motivation |
| 52 |
{ |
| 53 |
typedef int shared_mutex; // for exposition |
| 54 |
struct locker |
| 55 |
{ |
| 56 |
locker (); |
| 57 |
locker (int &r); |
| 58 |
~locker (); |
| 59 |
}; |
| 60 |
class protected_state |
| 61 |
{ |
| 62 |
shared_mutex mutex; // not a real mutex type |
| 63 |
int state; |
| 64 |
|
| 65 |
public: |
| 66 |
void not_thread_safe () |
| 67 |
{ |
| 68 |
locker (mutex); // { dg-warning "" } |
| 69 |
state++; // oops |
| 70 |
} |
| 71 |
|
| 72 |
void thread_safe () |
| 73 |
{ |
| 74 |
locker lock (mutex); |
| 75 |
state++; // ok; |
| 76 |
} |
| 77 |
}; |
| 78 |
} |