Fix test-suite fallout of default -Wreturn-type.
[official-gcc.git] / gcc / testsuite / g++.dg / warn / mvp.C
blob9fbe2272233e42e56ba45ebf1b7440402a01d7c0
1 // { dg-additional-options -Wparentheses }
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.
8 int (a); // { dg-warning "" }
9 int (*b);  // { dg-warning "" }
10 extern int (&c);  // { dg-warning "" }
12 int h1 = 0, h2 = 0;
13 struct H { H(...);};
15 namespace fns 
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.
28 namespace arys
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];
39 namespace complex
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        ());
51 namespace motivation
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;
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   };