/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
int y = (x); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
(void)y;
EFoo efoo = EFoo::Bar; switch (efoo) { case (EFoo::Bar): break; // expected-error {{parentheses immediately inside case statement [loplugin:unnecessaryparen]}}
}
int z = (y) ? 1 : 0; // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
(void)z;
int v1 = (static_cast<short>(1)) + 1; // expected-error {{unnecessary parentheses around cast [loplugin:unnecessaryparen]}}
(void)v1;
// No warnings, used to silence -Wunreachable-code: if ((false)) { return 0;
}
x = (true) ? 0 : 1;
// More "no warnings", at least potentially used to silence -Wunreachable-code: while ((false)) { return 0;
} for (; (false);) { return 0;
}
x = foo(0) && (false) ? 0 : 1;
x = MACRO < (0) ? 0 : 1; // cf. odd Clang -Wunreachable-code--suppression mechanism when the macro itself contains // parentheses, causing the issue that lead to c421ac3f9432f2e9468d28447dc4c2e45b6f4da3 // "Revert loplugin:unnecessaryparen warning around integer literals"
S s1; if ((s1)) { // expected-error {{parentheses immediately inside if statement [loplugin:unnecessaryparen]}} return 0;
}
S s2; if ((s2 = s1)) { return 0;
}
(void) sizeof (int);
(void) sizeof (x); // expect no warning (for whatever reason; for symmetry with above case?)
// Expecting just one error, not reported twice during TraverseInitListExpr: int a[] = {(x)}; // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
(void) a;
(void) (+1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
(void) (-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
// For simplicity's sake, even warn about pathological cases that would require adding // whitespace when removing the parentheses (as is also necessary in other cases anyway, like // "throw(x);"); it is unlikely that there are any actual occurrences of code like "-(-1)" that // would benefit from the parentheses readability-wise, compared to "- -1":
(void) -(-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.