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 #include <rtl/ustring.hxx>
14 #include <o3tl/typed_flags_set.hxx>
20 enum class EFoo
{ Bar
};
22 struct S
{ operator bool(); };
33 template <> struct typed_flags
<BrowseMode
> : is_typed_flags
<BrowseMode
, 0xf>
39 char const * operator ""_s1(char const *, std::size_t);
40 #if __cplusplus >= 202002L
41 struct Str
{ constexpr Str(char const *) {} };
42 template<Str
> char const * operator ""_s2();
48 x
= ((2)); // expected-error {{parentheses around parentheses [loplugin:unnecessaryparen]}}
50 if ((foo(1))) foo(2); // expected-error {{parentheses immediately inside if statement [loplugin:unnecessaryparen]}}
52 foo((1)); // expected-error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
54 int y
= (x
); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
57 EFoo efoo
= EFoo::Bar
;
59 case (EFoo::Bar
): break; // expected-error {{parentheses immediately inside case statement [loplugin:unnecessaryparen]}}
62 int z
= (y
) ? 1 : 0; // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
65 int v1
= (static_cast<short>(1)) + 1; // expected-error {{unnecessary parentheses around cast [loplugin:unnecessaryparen]}}
68 // No warnings, used to silence -Wunreachable-code:
74 // More "no warnings", at least potentially used to silence -Wunreachable-code:
81 x
= foo(0) && (false) ? 0 : 1;
82 x
= MACRO
< (0) ? 0 : 1;
83 // cf. odd Clang -Wunreachable-code--suppression mechanism when the macro itself contains
84 // parentheses, causing the issue that lead to c421ac3f9432f2e9468d28447dc4c2e45b6f4da3
85 // "Revert loplugin:unnecessaryparen warning around integer literals"
87 int v2
= (1); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
91 v3
= (std::string("xx") + "xx"); // expected-error {{parentheses immediately inside assignment [loplugin:unnecessaryparen]}}
95 if ((s1
)) { // expected-error {{parentheses immediately inside if statement [loplugin:unnecessaryparen]}}
104 (void) sizeof (x
); // expect no warning (for whatever reason; for symmetry with above case?)
106 // Expecting just one error, not reported twice during TraverseInitListExpr:
107 int a
[] = {(x
)}; // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
110 (void) (+1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
111 (void) (-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
113 // For simplicity's sake, even warn about pathological cases that would require adding
114 // whitespace when removing the parentheses (as is also necessary in other cases anyway, like
115 // "throw(x);"); it is unlikely that there are any actual occurrences of code like "-(-1)" that
116 // would benefit from the parentheses readability-wise, compared to "- -1":
117 (void) -(-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
120 delete (p
); // expected-error {{parentheses immediately inside delete expr [loplugin:unnecessaryparen]}}
122 BrowseMode nBits
= ( BrowseMode::Modules
| BrowseMode::Top
); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
125 OUString::number((v2
+1)); // expected-error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
127 (void) ("foo"); // expected-error {{unnecessary parentheses around single-token string literal [loplugin:unnecessaryparen]}}
128 (void) ("foo" "bar");
129 f(("foo")); // expected-error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
131 (void) ("foo"_s1
); // expected-error {{unnecessary parentheses around single-token string literal [loplugin:unnecessaryparen]}}
132 (void) ("foo" "bar"_s1
);
133 f(("foo"_s1
)); // expected-error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
135 #if __cplusplus >= 202002L
136 (void) ("foo"_s2
); //TODO: expected error {{unnecessary parentheses around single-token string literal [loplugin:unnecessaryparen]}}
137 (void) ("foo" "bar"_s2
);
138 f(("foo"_s2
)); // TODO: expected error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
143 struct B
{ operator bool() const; };
145 struct N
{ bool operator !(); };
155 return (p
) ? 1 : 0; // expected-error {{unnecessary parentheses around member expr [loplugin:unnecessaryparen]}}
158 static int foo3(Foo2
& foo
) {
162 return (foo
.p
) ? 1 : 0;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */