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/.
12 #include <rtl/ustring.hxx>
13 #include <o3tl/typed_flags_set.hxx>
19 enum class EFoo
{ Bar
};
21 struct S
{ operator bool(); };
32 template <> struct typed_flags
<BrowseMode
> : is_typed_flags
<BrowseMode
, 0xf>
40 x
= ((2)); // expected-error {{parentheses around parentheses [loplugin:unnecessaryparen]}}
42 if ((foo(1))) foo(2); // expected-error {{parentheses immediately inside if statement [loplugin:unnecessaryparen]}}
44 foo((1)); // expected-error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
46 int y
= (x
); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
49 EFoo efoo
= EFoo::Bar
;
51 case (EFoo::Bar
): break; // expected-error {{parentheses immediately inside case statement [loplugin:unnecessaryparen]}}
54 int z
= (y
) ? 1 : 0; // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
57 int v1
= (static_cast<short>(1)) + 1; // expected-error {{unnecessary parentheses around cast [loplugin:unnecessaryparen]}}
60 // No warnings, used to silence -Wunreachable-code:
66 // More "no warnings", at least potentially used to silence -Wunreachable-code:
73 x
= foo(0) && (false) ? 0 : 1;
74 x
= MACRO
< (0) ? 0 : 1;
75 // cf. odd Clang -Wunreachable-code--suppression mechanism when the macro itself contains
76 // parentheses, causing the issue that lead to c421ac3f9432f2e9468d28447dc4c2e45b6f4da3
77 // "Revert loplugin:unnecessaryparen warning around integer literals"
79 int v2
= (1); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
83 v3
= (std::string("xx") + "xx"); // expected-error {{parentheses immediately inside assignment [loplugin:unnecessaryparen]}}
87 if ((s1
)) { // expected-error {{parentheses immediately inside if statement [loplugin:unnecessaryparen]}}
96 (void) sizeof (x
); // expect no warning (for whatever reason; for symmetry with above case?)
98 // Expecting just one error, not reported twice during TraverseInitListExpr:
99 int a
[] = {(x
)}; // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
102 (void) (+1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
103 (void) (-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
105 // For simplicity's sake, even warn about pathological cases that would require adding
106 // whitespace when removing the parentheses (as is also necessary in other cases anyway, like
107 // "throw(x);"); it is unlikely that there are any actual occurrences of code like "-(-1)" that
108 // would benefit from the parentheses readability-wise, compared to "- -1":
109 (void) -(-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
112 delete (p
); // expected-error {{parentheses immediately inside delete expr [loplugin:unnecessaryparen]}}
114 BrowseMode nBits
= ( BrowseMode::Modules
| BrowseMode::Top
); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
124 return (p
) ? 1 : 0; // expected-error {{unnecessary parentheses around member expr [loplugin:unnecessaryparen]}}
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */