Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wuseless-cast3.C

raw
1 // PR c++/85043
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wuseless-cast" }
4
5 struct S { int s; void bump () { s++; } };
6
7 void
8 foo ()
9 {
10 S s = { 1 };
11 s.bump ();
12 S (s).bump (); // { dg-bogus "useless" }
13 ((S) s).bump (); // { dg-bogus "useless" }
14 static_cast<S> (s).bump (); // { dg-bogus "useless" }
15 }
16
17 struct X { };
18 void g(X&&);
19
20 void
21 f (X&& arg)
22 {
23 g(X(arg)); // { dg-bogus "useless" }
24 g(X(X{})); // { dg-warning "useless" }
25 g(static_cast<X&&>(arg));
26
27 int i = (int) 1; // { dg-warning "useless" }
28 const int &r = (int) i; // { dg-bogus "useless" }
29 }