1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 #define CAST_N3 (void) n3
14 #define ASSERT_N4 assert(n4 == 0)
15 #define ASSERT(x) assert(x)
18 int f1(int n1
, int n2
, int n3
, int n4
, int n5
) {
19 (void) n1
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
20 int const & r1
= n1
; // expected-note {{first consumption is here [loplugin:casttovoid]}}
21 (void) n2
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
22 int const & r2
= {n2
}; // expected-note {{first consumption is here [loplugin:casttovoid]}}
23 (void) n3
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
24 int const & r3
{n3
}; // expected-note {{first consumption is here [loplugin:casttovoid]}}
25 (void) n4
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
26 int const & r4(n4
); // expected-note {{first consumption is here [loplugin:casttovoid]}}
27 (void) n5
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
28 int const & r5
= (n5
); // expected-note {{first consumption is here [loplugin:casttovoid]}}
29 return r1
+ r2
+ r3
+ r4
+ r5
;
32 int const & f2(int const & n
) {
33 (void) n
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
34 return n
; // expected-note {{first consumption is here [loplugin:casttovoid]}}
37 int const & f3(int const & n
) {
38 (void) n
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
39 return (n
); // expected-note {{first consumption is here [loplugin:casttovoid]}}
42 int const & f4(int const & n
) {
43 (void) n
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
44 return {n
}; // expected-note {{first consumption is here [loplugin:casttovoid]}}
47 int const & f5(int const & n
) {
48 (void) n
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
49 return {(n
)}; // expected-note {{first consumption is here [loplugin:casttovoid]}}
54 n1_(n1
), // expected-note {{first consumption is here [loplugin:casttovoid]}}
55 n2_
{n2
} // expected-note {{first consumption is here [loplugin:casttovoid]}}
57 (void) n1
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
58 (void) n2
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
67 (void) s
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
68 return s
.n
; // expected-note {{first consumption is here [loplugin:casttovoid]}}
71 int const & fS2_2(S2
const & s
) {
72 (void) s
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
73 return s
.n
; // expected-note {{first consumption is here [loplugin:casttovoid]}}
76 // Don't trigger assert in CastToVoid::VisitReturnStmt:
77 int n
= [] { return 0; }();
81 int n2
= [](int const & n
) -> int const & {
82 (void) n
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
83 return n
; // expected-note {{first consumption is here [loplugin:casttovoid]}}
90 (void) n1
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
91 (void const) n1
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
92 (void volatile) n1
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
93 (void const volatile) n1
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
94 (void) (n1
); // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
95 (void) ((n1
)); // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
96 (void(n1
)); // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
97 static_cast<void>(n1
); // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
100 (void) n2
; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
113 assert(USE(n7
) == 0);
116 ASSERT(USE(USE(n8
== 0)));
120 return n1
// expected-note 8 {{first consumption is here [loplugin:casttovoid]}}
121 + n2
// expected-note {{first consumption is here [loplugin:casttovoid]}}
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */