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/.
11 #include <rtl/ustring.hxx>
17 enum class EFoo
{ Bar
};
19 struct S
{ operator bool(); };
24 x
= ((2)); // expected-error {{parentheses around parentheses [loplugin:unnecessaryparen]}}
26 if ((foo(1))) foo(2); // expected-error {{parentheses immediately inside if statement [loplugin:unnecessaryparen]}}
28 foo((1)); // expected-error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
30 int y
= (x
); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
33 EFoo efoo
= EFoo::Bar
;
35 case (EFoo::Bar
): break; // expected-error {{parentheses immediately inside case statement [loplugin:unnecessaryparen]}}
38 int z
= (y
) ? 1 : 0; // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
41 int v1
= (static_cast<short>(1)) + 1; // expected-error {{unnecessary parentheses around cast [loplugin:unnecessaryparen]}}
44 // No warnings, used to silence -Wunreachable-code:
50 // More "no warnings", at least potentially used to silence -Wunreachable-code:
57 x
= foo(0) && (false) ? 0 : 1;
58 x
= MACRO
< (0) ? 0 : 1;
59 // cf. odd Clang -Wunreachable-code--suppression mechanism when the macro itself contains
60 // parentheses, causing the issue that lead to c421ac3f9432f2e9468d28447dc4c2e45b6f4da3
61 // "Revert loplugin:unnecessaryparen warning around integer literals"
63 int v2
= (1); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
67 v3
= (std::string("xx") + "xx"); // expected-error {{parentheses immediately inside assignment [loplugin:unnecessaryparen]}}
71 if ((s1
)) { // expected-error {{parentheses immediately inside if statement [loplugin:unnecessaryparen]}}
80 (void) sizeof (x
); // expect no warning (for whatever reason; for symmetry with above case?)
82 // Expecting just one error, not reported twice during TraverseInitListExpr:
83 int a
[] = {(x
)}; // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
86 (void) (+1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
87 (void) (-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
89 // For simplicity's sake, even warn about pathological cases that would require adding
90 // whitespace when removing the parentheses (as is also necessary in other cases anyway, like
91 // "throw(x);"); it is unlikely that there are any actual occurrences of code like "-(-1)" that
92 // would benefit from the parentheses readability-wise, compared to "- -1":
93 (void) -(-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
96 delete (p
); // expected-error {{parentheses immediately inside delete expr [loplugin:unnecessaryparen]}}
105 (p
->GetText()).toChar(); // expected-error {{unnecessary parentheses around member expr [loplugin:unnecessaryparen]}}
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */