summaryrefslogtreecommitdiffstats
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-12-04 11:20:03 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-12-05 07:49:30 +0100
commite4472d3c139294499f4c0caeebd9d4e995958eb0 (patch)
tree3e62a6530f8b758dddab18981ee38cc76ecaef9e /compilerplugins
parentInclude vcl/outdev.hxx (diff)
downloadcore-e4472d3c139294499f4c0caeebd9d4e995958eb0.tar.gz
core-e4472d3c139294499f4c0caeebd9d4e995958eb0.zip
loplugin:unnecessaryparen include more assignments
Change-Id: I9fb8366634b31230b732dd38a98f800075529714 Reviewed-on: https://gerrit.libreoffice.org/64510 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/test/unnecessaryparen.cxx25
-rw-r--r--compilerplugins/clang/unnecessaryparen.cxx40
2 files changed, 48 insertions, 17 deletions
diff --git a/compilerplugins/clang/test/unnecessaryparen.cxx b/compilerplugins/clang/test/unnecessaryparen.cxx
index 8621fe9e8746..e89da95df384 100644
--- a/compilerplugins/clang/test/unnecessaryparen.cxx
+++ b/compilerplugins/clang/test/unnecessaryparen.cxx
@@ -9,6 +9,7 @@
#include <string>
#include <rtl/ustring.hxx>
+#include <o3tl/typed_flags_set.hxx>
#define MACRO (1)
@@ -18,6 +19,20 @@ enum class EFoo { Bar };
struct S { operator bool(); };
+enum class BrowseMode
+{
+ Modules = 0x01,
+ Top = 0x02,
+ Bottom = 0x04,
+ Left = 0x04,
+};
+namespace o3tl
+{
+template <> struct typed_flags<BrowseMode> : is_typed_flags<BrowseMode, 0xf>
+{
+};
+}
+
int main()
{
int x = 1;
@@ -94,15 +109,9 @@ int main()
char *p = nullptr;
delete (p); // expected-error {{parentheses immediately inside delete expr [loplugin:unnecessaryparen]}}
-};
-struct S2 {
- S2& GetText();
- void toChar();
-};
-void func2(S2 *p)
-{
- (p->GetText()).toChar(); // expected-error {{unnecessary parentheses around member expr [loplugin:unnecessaryparen]}}
+ BrowseMode nBits = ( BrowseMode::Modules | BrowseMode::Top ); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
+ (void)nBits;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx
index b2ad2951ec90..a39bcc813a63 100644
--- a/compilerplugins/clang/unnecessaryparen.cxx
+++ b/compilerplugins/clang/unnecessaryparen.cxx
@@ -386,7 +386,6 @@ bool UnnecessaryParen::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* callE
Opc != OO_AmpEqual && Opc != OO_CaretEqual &&
Opc != OO_PipeEqual)
return true;
-
auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(callExpr->getArg(1)));
if (!parenExpr)
return true;
@@ -395,9 +394,18 @@ bool UnnecessaryParen::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* callE
// Sometimes parentheses make the RHS of an assignment easier to read by
// visually disambiguating the = from a call to ==
auto sub = parenExpr->getSubExpr();
- if (isa<BinaryOperator>(sub)
- || isa<CXXOperatorCallExpr>(sub)
- || isa<ConditionalOperator>(sub))
+ if (auto subBinOp = dyn_cast<BinaryOperator>(sub))
+ {
+ if (!(subBinOp->isMultiplicativeOp() || subBinOp->isAdditiveOp() || subBinOp->isPtrMemOp()))
+ return true;
+ }
+ if (auto subOperatorCall = dyn_cast<CXXOperatorCallExpr>(sub))
+ {
+ auto op = subOperatorCall->getOperator();
+ if (!((op >= OO_Plus && op <= OO_Exclaim) || (op >= OO_ArrowStar && op <= OO_Subscript)))
+ return true;
+ }
+ if (isa<ConditionalOperator>(sub))
return true;
report(
@@ -420,12 +428,26 @@ bool UnnecessaryParen::VisitVarDecl(const VarDecl* varDecl)
return true;
if (compat::getBeginLoc(parenExpr).isMacroID())
return true;
+
+ // Sometimes parentheses make the RHS of an assignment easier to read by
+ // visually disambiguating the = from a call to ==
auto sub = parenExpr->getSubExpr();
- if (isa<BinaryOperator>(sub)
- || isa<CXXOperatorCallExpr>(sub)
- || isa<ConditionalOperator>(sub)
- // these two are for "parentheses were disambiguated as a function declaration [-Werror,-Wvexing-parse]"
- || isa<CXXBindTemporaryExpr>(sub)
+ if (auto subBinOp = dyn_cast<BinaryOperator>(sub))
+ {
+ if (!(subBinOp->isMultiplicativeOp() || subBinOp->isAdditiveOp() || subBinOp->isPtrMemOp()))
+ return true;
+ }
+ if (auto subOperatorCall = dyn_cast<CXXOperatorCallExpr>(sub))
+ {
+ auto op = subOperatorCall->getOperator();
+ if (!((op >= OO_Plus && op <= OO_Exclaim) || (op >= OO_ArrowStar && op <= OO_Subscript)))
+ return true;
+ }
+ if (isa<ConditionalOperator>(sub))
+ return true;
+
+ // these two are for "parentheses were disambiguated as a function declaration [-Werror,-Wvexing-parse]"
+ if (isa<CXXBindTemporaryExpr>(sub)
|| isa<CXXFunctionalCastExpr>(sub))
return true;