[Libreoffice-commits] core.git: accessibility/source chart2/source codemaker/source compilerplugins/clang connectivity/source filter/source forms/source idlc/source sal/osl sc/qa sc/source sdext/source sd/qa sd/source svtools/source sw/source unodevtools/source vcl/source xmlsecurity/source

Stephan Bergmann sbergman at redhat.com
Mon Nov 27 13:05:18 UTC 2017


 accessibility/source/standard/vclxaccessiblebox.cxx |    2 
 chart2/source/tools/ObjectIdentifier.cxx            |    2 
 codemaker/source/codemaker/typemanager.cxx          |    2 
 codemaker/source/cppumaker/cpputype.cxx             |   20 +--
 codemaker/source/cppumaker/includes.cxx             |   14 +-
 compilerplugins/clang/test/unnecessaryparen.cxx     |    8 -
 compilerplugins/clang/unnecessaryparen.cxx          |  115 +++++++++++++-------
 connectivity/source/drivers/dbase/DTable.cxx        |    2 
 filter/source/svg/parserfragments.cxx               |    2 
 forms/source/component/imgprod.cxx                  |   10 -
 idlc/source/astexpression.cxx                       |    2 
 sal/osl/unx/file.cxx                                |    2 
 sal/osl/unx/file_volume.cxx                         |    2 
 sc/qa/unit/ucalc_pivottable.cxx                     |    4 
 sc/source/ui/dbgui/csvruler.cxx                     |    2 
 sd/qa/unit/import-tests.cxx                         |    8 -
 sd/source/ui/unoidl/unomodel.cxx                    |    2 
 sdext/source/minimizer/optimizerdialogcontrols.cxx  |    6 -
 svtools/source/svhtml/parhtml.cxx                   |    2 
 sw/source/filter/ww8/ww8atr.cxx                     |    2 
 sw/source/ui/envelp/envfmt.cxx                      |    4 
 sw/source/uibase/config/caption.cxx                 |    2 
 unodevtools/source/skeletonmaker/skeletonmaker.cxx  |    2 
 vcl/source/outdev/text.cxx                          |    2 
 xmlsecurity/source/framework/saxeventkeeperimpl.cxx |    4 
 25 files changed, 134 insertions(+), 89 deletions(-)

New commits:
commit a2656563f1a7639a99276fda90b6c8f675d20fc5
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Nov 27 09:46:06 2017 +0100

    loplugin:unnecessaryparen: Warn about parentheses around literals
    
    ...that are not composed of multiple tokens, like ("foo" "bar").  Also don't yet
    warn about Boolean literals, which are sometimes wrapped in parentheses to
    silence unreachable-code warnings.
    
    To avoid multiple warnings about code like
    
      f((0))
    
    switch to generally using a set of ParenExpr to keep track of which occurrences
    have already been handled.
    
    Change-Id: I036a25a92836ec6ab6c56ea848f71bc6d63822bc
    Reviewed-on: https://gerrit.libreoffice.org/45317
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/accessibility/source/standard/vclxaccessiblebox.cxx b/accessibility/source/standard/vclxaccessiblebox.cxx
index a7bf5306e68c..03d095d845d4 100644
--- a/accessibility/source/standard/vclxaccessiblebox.cxx
+++ b/accessibility/source/standard/vclxaccessiblebox.cxx
@@ -470,7 +470,7 @@ Any VCLXAccessibleBox::getCurrentValue( )
         {
             if(pList->getSelectedAccessibleChildCount()>0)
             {
-                Reference<XAccessibleContext> xName (pList->getSelectedAccessibleChild((sal_Int32)(0)), UNO_QUERY);
+                Reference<XAccessibleContext> xName (pList->getSelectedAccessibleChild((sal_Int32)0), UNO_QUERY);
                 if(xName.is())
                 {
                     aAny <<= xName->getAccessibleName();
diff --git a/chart2/source/tools/ObjectIdentifier.cxx b/chart2/source/tools/ObjectIdentifier.cxx
index cb25bb066101..0244657476a5 100644
--- a/chart2/source/tools/ObjectIdentifier.cxx
+++ b/chart2/source/tools/ObjectIdentifier.cxx
@@ -1136,7 +1136,7 @@ OUString ObjectIdentifier::createSeriesSubObjectStub( ObjectType eSubObjectType
                     , const OUString& rDragMethodServiceName
                     , const OUString& rDragParameterString )
 {
-    OUString aChildParticle = getStringForType( eSubObjectType ) + ("=");
+    OUString aChildParticle = getStringForType( eSubObjectType ) + "=";
 
     return createClassifiedIdentifierForParticles(
             rSeriesParticle, aChildParticle
diff --git a/codemaker/source/codemaker/typemanager.cxx b/codemaker/source/codemaker/typemanager.cxx
index b37f14edca69..345594a38b1f 100644
--- a/codemaker/source/codemaker/typemanager.cxx
+++ b/codemaker/source/codemaker/typemanager.cxx
@@ -252,7 +252,7 @@ codemaker::UnoType::Sort TypeManager::decompose(
         default:
             throw CannotDumpException(
                 "unexpected \"" + n + "\" resolved from \"" + name
-                + ("\"in call to TypeManager::decompose"));
+                + "\"in call to TypeManager::decompose");
         }
     }
 }
diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx
index 36014c13460b..ba84a46b75f4 100644
--- a/codemaker/source/cppumaker/cpputype.cxx
+++ b/codemaker/source/cppumaker/cpputype.cxx
@@ -1402,7 +1402,7 @@ void InterfaceType::dumpCppuAttributeRefs(FileStream & out, sal_uInt32 & index)
             << "],\n";
         inc(38);
         out << indent()
-            << ("(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_ATTRIBUTE,\n")
+            << "(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_ATTRIBUTE,\n"
             << indent() << "sAttributeName" << n << ".pData );\n";
         dec(38);
         ++n;
@@ -1419,7 +1419,7 @@ void InterfaceType::dumpCppuMethodRefs(FileStream & out, sal_uInt32 & index)
             << "],\n";
         inc(38);
         out << indent()
-            << ("(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_METHOD,\n")
+            << "(typelib_TypeClass)::css::uno::TypeClass_INTERFACE_METHOD,\n"
             << indent() << "sMethodName" << n << ".pData );\n";
         dec(38);
         ++n;
@@ -1965,7 +1965,7 @@ void PlainStructType::dumpLightGetCppuType(FileStream & out)
         << getTypeClass(name_, true) << ", \"" << name_ << "\");\n";
     dec();
     out << indent() << "}\n" << indent()
-        << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
+        << "return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n";
     dumpGetCppuTypePostamble(out);
 }
 
@@ -2005,7 +2005,7 @@ void PlainStructType::dumpNormalGetCppuType(FileStream & out)
     out << ", " << entity_->getDirectMembers().size() << ", the_members, 0);\n";
     dec();
     out << indent() << "}\n" << indent()
-        << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
+        << "return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n";
     dumpGetCppuTypePostamble(out);
 }
 
@@ -2418,7 +2418,7 @@ void PolyStructType::dumpLightGetCppuType(FileStream & out)
         << ", the_buffer.getStr());\n";
     dec();
     out << indent() << "}\n" << indent()
-        << ("return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n");
+        << "return *reinterpret_cast< ::css::uno::Type * >(&the_type);\n";
     dumpGetCppuTypePostamble(out);
 }
 
@@ -3558,7 +3558,7 @@ void ServiceType::dumpHppFile(
                 o << indent() << "throw;\n";
                 dec();
                 o << indent()
-                  << ("} catch (const ::css::uno::Exception & the_exception) {\n");
+                  << "} catch (const ::css::uno::Exception & the_exception) {\n";
                 inc();
                 o << indent() << "throw ::css::uno::DeploymentException(";
                 failsToSupply(o, name_, baseName);
@@ -3603,7 +3603,7 @@ void ServiceType::dumpHppFile(
                 o << indent() << "assert(the_context.is());\n";
                 if (!rest && !cons.parameters.empty()) {
                     o << indent()
-                      << ("::css::uno::Sequence< ::css::uno::Any > the_arguments(")
+                      << "::css::uno::Sequence< ::css::uno::Any > the_arguments("
                       << cons.parameters.size() << ");\n";
                     std::vector<
                     unoidl::SingleInterfaceBasedServiceEntity::Constructor::
@@ -3681,7 +3681,7 @@ void ServiceType::dumpHppFile(
                     o << "the_arguments";
                 }
                 o << ");\n" << indent() << "}\n";
-                o << ("#else\n")
+                o << "#else\n"
                   << indent() << "the_instance = ::css::uno::Reference< "
                   << scopedBaseName
                   << (" >(the_context->getServiceManager()->"
@@ -3693,7 +3693,7 @@ void ServiceType::dumpHppFile(
                           u2b(cons.parameters.back().name), "param",
                           codemaker::cpp::IdentifierTranslationMode::NonGlobal);
                 } else if (cons.parameters.empty()) {
-                    o << ("::css::uno::Sequence< ::css::uno::Any >()");
+                    o << "::css::uno::Sequence< ::css::uno::Any >()";
                 } else {
                     o << "the_arguments";
                 }
@@ -3701,7 +3701,7 @@ void ServiceType::dumpHppFile(
                 if (!tree.getRoot().present) {
                     dec();
                     o << indent()
-                      << ("} catch (const ::css::uno::RuntimeException &) {\n");
+                      << "} catch (const ::css::uno::RuntimeException &) {\n";
                     inc();
                     o << indent() << "throw;\n";
                     dec();
diff --git a/codemaker/source/cppumaker/includes.cxx b/codemaker/source/cppumaker/includes.cxx
index b317ff05784b..e33262ee7f6c 100644
--- a/codemaker/source/cppumaker/includes.cxx
+++ b/codemaker/source/cppumaker/includes.cxx
@@ -201,11 +201,11 @@ void Includes::dump(
     }
     if (m_includeCppuMacrosHxx) {
         dumpEmptyLineBeforeFirst(out, &first);
-        out << ("#include \"cppu/macros.hxx\"\n");
+        out << "#include \"cppu/macros.hxx\"\n";
     }
     if (m_includeCppuUnotypeHxx) {
         dumpEmptyLineBeforeFirst(out, &first);
-        out << ("#include \"cppu/unotype.hxx\"\n");
+        out << "#include \"cppu/unotype.hxx\"\n";
     }
     if (m_includeOslMutexHxx) {
         dumpEmptyLineBeforeFirst(out, &first);
@@ -213,7 +213,7 @@ void Includes::dump(
     }
     if (m_includeRtlStrbufHxx) {
         dumpEmptyLineBeforeFirst(out, &first);
-        out << ("#include \"rtl/strbuf.hxx\"\n");
+        out << "#include \"rtl/strbuf.hxx\"\n";
     }
     if (m_includeRtlStringH) {
         dumpEmptyLineBeforeFirst(out, &first);
@@ -225,7 +225,7 @@ void Includes::dump(
     }
     if (m_includeRtlUstrbufHxx) {
         dumpEmptyLineBeforeFirst(out, &first);
-        out << ("#include \"rtl/ustrbuf.hxx\"\n");
+        out << "#include \"rtl/ustrbuf.hxx\"\n";
     }
     if (m_includeRtlUstringH) {
         dumpEmptyLineBeforeFirst(out, &first);
@@ -233,7 +233,7 @@ void Includes::dump(
     }
     if (m_includeRtlUstringHxx) {
         dumpEmptyLineBeforeFirst(out, &first);
-        out << ("#include \"rtl/ustring.hxx\"\n");
+        out << "#include \"rtl/ustring.hxx\"\n";
     }
     if (m_includeRtlInstanceHxx) {
         dumpEmptyLineBeforeFirst(out, &first);
@@ -245,11 +245,11 @@ void Includes::dump(
     }
     if (m_includeTypelibTypeclassH) {
         dumpEmptyLineBeforeFirst(out, &first);
-        out << ("#include \"typelib/typeclass.h\"\n");
+        out << "#include \"typelib/typeclass.h\"\n";
     }
     if (m_includeTypelibTypedescriptionH) {
         dumpEmptyLineBeforeFirst(out, &first);
-        out << ("#include \"typelib/typedescription.h\"\n");
+        out << "#include \"typelib/typedescription.h\"\n";
     }
 }
 
diff --git a/compilerplugins/clang/test/unnecessaryparen.cxx b/compilerplugins/clang/test/unnecessaryparen.cxx
index 8a6a84468903..7c5f525a1857 100644
--- a/compilerplugins/clang/test/unnecessaryparen.cxx
+++ b/compilerplugins/clang/test/unnecessaryparen.cxx
@@ -25,7 +25,7 @@ int main()
 
     foo((1)); // expected-error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
 
-    int y = (x); // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}} expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
+    int y = (x); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
     (void)y;
 
     EFoo foo = EFoo::Bar;
@@ -54,8 +54,6 @@ int main()
 
     S s1;
     if ((s1)) { // expected-error {{parentheses immediately inside if statement [loplugin:unnecessaryparen]}}
-        // expected-error at -1 {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
-        // expected-error at -2 {{unnecessary parentheses around member expr [loplugin:unnecessaryparen]}}
         return 0;
     }
     S s2;
@@ -65,6 +63,10 @@ int main()
 
     (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;
 };
 
 struct S2 {
diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx
index dcf65f0c0234..046176a64150 100644
--- a/compilerplugins/clang/unnecessaryparen.cxx
+++ b/compilerplugins/clang/unnecessaryparen.cxx
@@ -12,6 +12,7 @@
 #include <iostream>
 #include <fstream>
 #include <set>
+#include <unordered_set>
 
 #include <clang/AST/CXXInheritance.h>
 #include "compat.hxx"
@@ -81,33 +82,37 @@ public:
     bool VisitCallExpr(const CallExpr *);
     bool VisitVarDecl(const VarDecl *);
     bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *);
-    bool TraverseUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *);
-    bool TraverseCaseStmt(CaseStmt *);
+    bool VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr const *);
+    bool VisitConditionalOperator(ConditionalOperator const * expr);
     bool VisitMemberExpr(const MemberExpr *f);
 private:
     void VisitSomeStmt(Stmt const * stmt, const Expr* cond, StringRef stmtName);
-    Expr const * insideSizeof = nullptr;
-    Expr const * insideCaseStmt = nullptr;
+
+    // Hack for libxml2's BAD_CAST object-like macro (expanding to "(xmlChar *)"), which is
+    // typically used as if it were a function-like macro, e.g., as "BAD_CAST(pName)" in
+    // SwNode::dumpAsXml (sw/source/core/docnode/node.cxx):
+    bool isPrecededBy_BAD_CAST(Expr const * expr);
+
+    std::unordered_set<ParenExpr const *> handled_;
 };
 
-bool UnnecessaryParen::TraverseUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr * expr)
+bool UnnecessaryParen::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr const * expr)
 {
-    auto old = insideSizeof;
     if (expr->getKind() == UETT_SizeOf && !expr->isArgumentType()) {
-        insideSizeof = ignoreAllImplicit(expr->getArgumentExpr());
+        if (auto const e = dyn_cast<ParenExpr>(ignoreAllImplicit(expr->getArgumentExpr()))) {
+            handled_.insert(e);
+        }
     }
-    bool ret = RecursiveASTVisitor::TraverseUnaryExprOrTypeTraitExpr(expr);
-    insideSizeof = old;
-    return ret;
+    return true;
 }
 
-bool UnnecessaryParen::TraverseCaseStmt(CaseStmt * caseStmt)
-{
-    auto old = insideCaseStmt;
-    insideCaseStmt = ignoreAllImplicit(caseStmt->getLHS());
-    bool ret = RecursiveASTVisitor::TraverseCaseStmt(caseStmt);
-    insideCaseStmt = old;
-    return ret;
+bool UnnecessaryParen::VisitConditionalOperator(ConditionalOperator const * expr) {
+    if (auto const e = dyn_cast<ParenExpr>(ignoreAllImplicit(expr->getCond()))) {
+        if (isa<CXXBoolLiteralExpr>(e->getSubExpr())) {
+            handled_.insert(e);
+        }
+    }
+    return true;
 }
 
 bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr)
@@ -116,9 +121,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr)
         return true;
     if (parenExpr->getLocStart().isMacroID())
         return true;
-    if (insideSizeof && parenExpr == insideSizeof)
-        return true;
-    if (insideCaseStmt && parenExpr == insideCaseStmt)
+    if (handled_.find(parenExpr) != handled_.end())
         return true;
 
     auto subExpr = ignoreAllImplicit(parenExpr->getSubExpr());
@@ -131,32 +134,53 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr)
             DiagnosticsEngine::Warning, "parentheses around parentheses",
             parenExpr->getLocStart())
             << parenExpr->getSourceRange();
+        handled_.insert(subParenExpr);
     }
 
-    if (auto declRefExpr = dyn_cast<DeclRefExpr>(subExpr)) {
-        // hack for libxml2's BAD_CAST object-like macro (expanding to "(xmlChar *)"), which is
-        // typically used as if it were a function-like macro, e.g., as "BAD_CAST(pName)" in
-        // SwNode::dumpAsXml (sw/source/core/docnode/node.cxx)
-        if (!declRefExpr->getLocStart().isMacroID()) {
-            SourceManager& SM = compiler.getSourceManager();
-            const char *p1 = SM.getCharacterData( declRefExpr->getLocStart().getLocWithOffset(-10) );
-            const char *p2 = SM.getCharacterData( declRefExpr->getLocStart() );
-            if ( std::string(p1, p2 - p1).find("BAD_CAST") != std::string::npos )
-                return true;
+    // Somewhat redundantly add parenExpr to handled_, so that issues within InitListExpr don't get
+    // reported twice (without having to change TraverseInitListExpr to only either traverse the
+    // syntactic or semantic form, as other plugins do):
+
+    if (isa<DeclRefExpr>(subExpr)) {
+        if (!isPrecededBy_BAD_CAST(parenExpr)) {
+            report(
+                DiagnosticsEngine::Warning, "unnecessary parentheses around identifier",
+                parenExpr->getLocStart())
+                << parenExpr->getSourceRange();
+            handled_.insert(parenExpr);
+        }
+    } else if (isa<IntegerLiteral>(subExpr) || isa<CharacterLiteral>(subExpr)
+               || isa<FloatingLiteral>(subExpr) || isa<ImaginaryLiteral>(subExpr)
+               || isa<CXXNullPtrLiteralExpr>(subExpr))
+        //TODO: isa<CXXBoolLiteralExpr>(subExpr) || isa<ObjCBoolLiteralExpr>(subExpr)
+    {
+        auto const loc = subExpr->getLocStart();
+        if (loc.isMacroID() && compiler.getSourceManager().isAtStartOfImmediateMacroExpansion(loc))
+        {
+            // just in case the macro could also expand to something that /would/ require
+            // parentheses here
+            return true;
         }
-
         report(
-            DiagnosticsEngine::Warning, "unnecessary parentheses around identifier",
+            DiagnosticsEngine::Warning, "unnecessary parentheses around literal",
             parenExpr->getLocStart())
             << parenExpr->getSourceRange();
-    }
-
-
-    if (isa<CXXNamedCastExpr>(subExpr)) {
+        handled_.insert(parenExpr);
+    } else if (auto const e = dyn_cast<clang::StringLiteral>(subExpr)) {
+        if (e->getNumConcatenated() == 1 && !isPrecededBy_BAD_CAST(parenExpr)) {
+            report(
+                DiagnosticsEngine::Warning,
+                "unnecessary parentheses around single-token string literal",
+                parenExpr->getLocStart())
+                << parenExpr->getSourceRange();
+            handled_.insert(parenExpr);
+        }
+    } else if (isa<CXXNamedCastExpr>(subExpr)) {
         report(
             DiagnosticsEngine::Warning, "unnecessary parentheses around cast",
             parenExpr->getLocStart())
             << parenExpr->getSourceRange();
+        handled_.insert(parenExpr);
     }
 
     return true;
@@ -217,6 +241,7 @@ bool UnnecessaryParen::VisitReturnStmt(const ReturnStmt* returnStmt)
             DiagnosticsEngine::Warning, "parentheses immediately inside return statement",
             parenExpr->getLocStart())
             << parenExpr->getSourceRange();
+        handled_.insert(parenExpr);
     }
     return true;
 }
@@ -234,6 +259,7 @@ void UnnecessaryParen::VisitSomeStmt(const Stmt * stmt, const Expr* cond, String
         if (isa<CXXBoolLiteralExpr>(parenExpr->getSubExpr())
             && stmtName == "if")
         {
+            handled_.insert(parenExpr);
             return;
         }
         // assignments need extra parentheses or they generate a compiler warning
@@ -250,6 +276,7 @@ void UnnecessaryParen::VisitSomeStmt(const Stmt * stmt, const Expr* cond, String
             parenExpr->getLocStart())
             << stmtName
             << parenExpr->getSourceRange();
+        handled_.insert(parenExpr);
     }
 }
 
@@ -273,6 +300,7 @@ bool UnnecessaryParen::VisitCallExpr(const CallExpr* callExpr)
         DiagnosticsEngine::Warning, "parentheses immediately inside single-arg call",
         parenExpr->getLocStart())
         << parenExpr->getSourceRange();
+    handled_.insert(parenExpr);
     return true;
 }
 
@@ -311,6 +339,7 @@ bool UnnecessaryParen::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* callE
         DiagnosticsEngine::Warning, "parentheses immediately inside assignment",
         parenExpr->getLocStart())
         << parenExpr->getSourceRange();
+    handled_.insert(parenExpr);
     return true;
 }
 
@@ -339,6 +368,7 @@ bool UnnecessaryParen::VisitVarDecl(const VarDecl* varDecl)
         DiagnosticsEngine::Warning, "parentheses immediately inside vardecl statement",
         parenExpr->getLocStart())
         << parenExpr->getSourceRange();
+    handled_.insert(parenExpr);
     return true;
 }
 
@@ -350,6 +380,8 @@ bool UnnecessaryParen::VisitMemberExpr(const MemberExpr* memberExpr)
     auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(memberExpr->getBase()));
     if (!parenExpr)
         return true;
+    if (handled_.find(parenExpr) != handled_.end())
+        return true;
     if (parenExpr->getLocStart().isMacroID())
         return true;
 
@@ -370,9 +402,20 @@ bool UnnecessaryParen::VisitMemberExpr(const MemberExpr* memberExpr)
         DiagnosticsEngine::Warning, "unnecessary parentheses around member expr",
         parenExpr->getLocStart())
         << parenExpr->getSourceRange();
+    handled_.insert(parenExpr);
     return true;
 }
 
+bool UnnecessaryParen::isPrecededBy_BAD_CAST(Expr const * expr) {
+    if (expr->getLocStart().isMacroID()) {
+        return false;
+    }
+    SourceManager& SM = compiler.getSourceManager();
+    const char *p1 = SM.getCharacterData( expr->getLocStart().getLocWithOffset(-10) );
+    const char *p2 = SM.getCharacterData( expr->getLocStart() );
+    return std::string(p1, p2 - p1).find("BAD_CAST") != std::string::npos;
+}
+
 loplugin::Plugin::Registration< UnnecessaryParen > X("unnecessaryparen", true);
 
 }
diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx
index 22d9f441b1f0..3629bfebdb5d 100644
--- a/connectivity/source/drivers/dbase/DTable.cxx
+++ b/connectivity/source/drivers/dbase/DTable.cxx
@@ -156,7 +156,7 @@ void lcl_CalDate(sal_Int32 _nJulianDate,sal_Int32 _nJulianTime,css::util::DateTi
         sal_Int32 ka = _nJulianDate;
         if ( _nJulianDate >= 2299161 )
         {
-            ialp = (sal_Int32)( ((double) _nJulianDate - 1867216.25 ) / ( 36524.25 ));
+            ialp = (sal_Int32)( ((double) _nJulianDate - 1867216.25 ) / 36524.25 );
             ka = _nJulianDate + 1 + ialp - ( ialp >> 2 );
         }
         sal_Int32 kb = ka + 1524;
diff --git a/filter/source/svg/parserfragments.cxx b/filter/source/svg/parserfragments.cxx
index e6afdefbab09..02c37089cf0d 100644
--- a/filter/source/svg/parserfragments.cxx
+++ b/filter/source/svg/parserfragments.cxx
@@ -545,7 +545,7 @@ bool parsePaintUri( std::pair<const char*,const char*>& o_rPaintUri,
     const bool bRes = parse(sPaintUri,
         //  Begin grammar
         (
-            str_p("url(") >> !( str_p("'") ) >> ("#") >>
+            str_p("url(") >> !( str_p("'") ) >> "#" >>
             (+(anychar_p - (str_p("'") | str_p(")"))))[assign_a(o_rPaintUri)] >>
             !( str_p("'") ) >> str_p(")") >>
             *( str_p("none")[assign_a(io_rColor.second,false)] |
diff --git a/forms/source/component/imgprod.cxx b/forms/source/component/imgprod.cxx
index 7424b92aacfe..cfa5e528afcc 100644
--- a/forms/source/component/imgprod.cxx
+++ b/forms/source/component/imgprod.cxx
@@ -355,16 +355,16 @@ void ImageProducer::ImplInitConsumer( const Graphic& rGraphic )
                 {
                     const BitmapColor& rCol = pBmpAcc->GetPaletteColor( (sal_uInt16) i );
 
-                    *pTmp = ( (sal_Int32) rCol.GetRed() ) << (sal_Int32)(24);
-                    *pTmp |= ( (sal_Int32) rCol.GetGreen() ) << (sal_Int32)(16);
-                    *pTmp |= ( (sal_Int32) rCol.GetBlue() ) << (sal_Int32)(8);
-                    *pTmp |= (sal_Int32)(0x000000ffL);
+                    *pTmp = ( (sal_Int32) rCol.GetRed() ) << (sal_Int32)24;
+                    *pTmp |= ( (sal_Int32) rCol.GetGreen() ) << (sal_Int32)16;
+                    *pTmp |= ( (sal_Int32) rCol.GetBlue() ) << (sal_Int32)8;
+                    *pTmp |= (sal_Int32)0x000000ffL;
                 }
 
                 if( rGraphic.IsTransparent() )
                 {
                     // append transparent entry
-                    *pTmp = (sal_Int32)(0xffffff00L);
+                    *pTmp = (sal_Int32)0xffffff00L;
                     mnTransIndex = nPalCount;
                     nPalCount++;
                 }
diff --git a/idlc/source/astexpression.cxx b/idlc/source/astexpression.cxx
index c1563a3dfb14..5da3616e1c00 100644
--- a/idlc/source/astexpression.cxx
+++ b/idlc/source/astexpression.cxx
@@ -1083,7 +1083,7 @@ const sal_Char* SAL_CALL exprTypeToString(ExprType t)
             return "none";
     }
 
-    return ("unknown");
+    return "unknown";
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index de36b3d26a9c..c7d6522ff3d0 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -289,7 +289,7 @@ oslFileError FileHandle_Impl::setPos(sal_uInt64 uPos)
 
 sal_uInt64 FileHandle_Impl::getSize() const
 {
-    off_t const bufend = std::max((off_t)(0), m_bufptr) + m_buflen;
+    off_t const bufend = std::max((off_t)0, m_bufptr) + m_buflen;
     return std::max(m_size, sal::static_int_cast< sal_uInt64 >(bufend));
 }
 
diff --git a/sal/osl/unx/file_volume.cxx b/sal/osl/unx/file_volume.cxx
index 5dc41cc0f7ea..116874569b62 100644
--- a/sal/osl/unx/file_volume.cxx
+++ b/sal/osl/unx/file_volume.cxx
@@ -216,7 +216,7 @@ static oslFileError osl_psz_getVolumeInformation (
     {
         OSL_detail_STATFS_STRUCT sfs;
         OSL_detail_STATFS_INIT(sfs);
-        if ((OSL_detail_STATFS(pszDirectory, &sfs)) < (0))
+        if ((OSL_detail_STATFS(pszDirectory, &sfs)) < 0)
         {
             oslFileError result = oslTranslateFileError(errno);
             return result;
diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx
index 404de5d06c14..ca7c88f196b5 100644
--- a/sc/qa/unit/ucalc_pivottable.cxx
+++ b/sc/qa/unit/ucalc_pivottable.cxx
@@ -2194,11 +2194,11 @@ void Test::testFuncGETPIVOTDATA()
     aPivotPosStr = aOutRange.aStart.Format(ScRefFlags::ADDR_ABS);
 
     // First, get the grand totals.
-    aFormula = ("=GETPIVOTDATA(\"Sum - Value\";") + aPivotPosStr + ")";
+    aFormula = "=GETPIVOTDATA(\"Sum - Value\";" + aPivotPosStr + ")";
     m_pDoc->SetString(aPos, aFormula);
     fVal = m_pDoc->GetValue(aPos);
     CPPUNIT_ASSERT_EQUAL(21.0, fVal);
-    aFormula = ("=GETPIVOTDATA(\"Count - Value\";") + aPivotPosStr + ")";
+    aFormula = "=GETPIVOTDATA(\"Count - Value\";" + aPivotPosStr + ")";
     m_pDoc->SetString(aPos, aFormula);
     fVal = m_pDoc->GetValue(aPos);
     CPPUNIT_ASSERT_EQUAL(6.0, fVal);
diff --git a/sc/source/ui/dbgui/csvruler.cxx b/sc/source/ui/dbgui/csvruler.cxx
index 00e85c71f78b..5c8b1f6489e5 100644
--- a/sc/source/ui/dbgui/csvruler.cxx
+++ b/sc/source/ui/dbgui/csvruler.cxx
@@ -567,7 +567,7 @@ void ScCsvRuler::ImplDrawBackgrDev()
     maBackgrDev->SetFillColor();
     sal_Int32 nPos;
 
-    sal_Int32 nFirstPos = std::max( GetPosFromX( 0 ) - 1, (sal_Int32)(0) );
+    sal_Int32 nFirstPos = std::max( GetPosFromX( 0 ) - 1, (sal_Int32)0 );
     sal_Int32 nLastPos = GetPosFromX( GetWidth() );
     sal_Int32 nY = (maActiveRect.Top() + maActiveRect.Bottom()) / 2;
     for( nPos = nFirstPos; nPos <= nLastPos; ++nPos )
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 00e72e3b533c..0d2ede053bae 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -1323,9 +1323,9 @@ void SdImportTest::testTdf93124()
 
     uno::Sequence< beans::PropertyValue > aFilterData(2);
     aFilterData[0].Name = "PixelWidth";
-    aFilterData[0].Value <<= (sal_Int32)(320);
+    aFilterData[0].Value <<= (sal_Int32)320;
     aFilterData[1].Name = "PixelHeight";
-    aFilterData[1].Value <<= (sal_Int32)(180);
+    aFilterData[1].Value <<= (sal_Int32)180;
 
     utl::TempFile aTempFile;
     aTempFile.EnableKillingFile();
@@ -1399,9 +1399,9 @@ void SdImportTest::testTdf99729()
 
         uno::Sequence< beans::PropertyValue > aFilterData(2);
         aFilterData[0].Name = "PixelWidth";
-        aFilterData[0].Value <<= (sal_Int32)(320);
+        aFilterData[0].Value <<= (sal_Int32)320;
         aFilterData[1].Name = "PixelHeight";
-        aFilterData[1].Value <<= (sal_Int32)(240);
+        aFilterData[1].Value <<= (sal_Int32)240;
 
         utl::TempFile aTempFile;
         aTempFile.EnableKillingFile();
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index d3c6d2ee0877..2699b62bb97f 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -1116,7 +1116,7 @@ uno::Sequence< OUString > SAL_CALL SdXImpressDocument::getAvailableServiceNames(
 
     const uno::Sequence< OUString > aSNS_ORG( SvxFmMSFactory::getAvailableServiceNames() );
 
-    uno::Sequence< OUString > aSNS( mbImpressDoc ? (36) : (19) );
+    uno::Sequence< OUString > aSNS( mbImpressDoc ? 36 : 19 );
 
     sal_uInt16 i(0);
 
diff --git a/sdext/source/minimizer/optimizerdialogcontrols.cxx b/sdext/source/minimizer/optimizerdialogcontrols.cxx
index 3c996f8c8b56..f6d575849273 100644
--- a/sdext/source/minimizer/optimizerdialogcontrols.cxx
+++ b/sdext/source/minimizer/optimizerdialogcontrols.cxx
@@ -838,9 +838,9 @@ void OptimizerDialog::InitPage4()
             Any( OUString("STR_SAVE_AS") ),
             Any( (sal_Int32)( PAGE_POS_X + 6 ) ),
             Any( (sal_Int32)( DIALOG_HEIGHT - 75 ) ),
-            Any( (sal_Int32)( 0 ) ),
-            Any( (sal_Int32)( 100 ) ),
-            Any( (sal_Int32)( 0 ) ),
+            Any( (sal_Int32)0 ),
+            Any( (sal_Int32)100 ),
+            Any( (sal_Int32)0 ),
             Any( (sal_Int32)( PAGE_WIDTH - 12 ) ) };
 
         sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx
index 1eb82b6bb788..ec8f7f5db683 100644
--- a/svtools/source/svhtml/parhtml.cxx
+++ b/svtools/source/svhtml/parhtml.cxx
@@ -1411,7 +1411,7 @@ const HTMLOptions& HTMLParser::GetOptions( HtmlOptionId const *pNoConvertToken )
                 {
                     sal_Int32 nLen = 0;
                     nStt = nPos;
-                    if( ('"'==cChar) || ('\'')==cChar )
+                    if( ('"'==cChar) || '\''==cChar )
                     {
                         sal_Unicode cEnd = cChar;
                         nPos++; nStt++;
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index c75ad43df571..34a448ef2690 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -1461,7 +1461,7 @@ void WW8AttributeOutput::CharBidiRTL( const SfxPoolItem& rHt )
     if( rAttr.GetValue() == 1 )
     {
         m_rWW8Export.InsUInt16(0x85a);
-        m_rWW8Export.pO->push_back((sal_uInt8)(1));
+        m_rWW8Export.pO->push_back((sal_uInt8)1);
     }
 }
 
diff --git a/sw/source/ui/envelp/envfmt.cxx b/sw/source/ui/envelp/envfmt.cxx
index 0dc857836407..cdc602bcb29a 100644
--- a/sw/source/ui/envelp/envfmt.cxx
+++ b/sw/source/ui/envelp/envfmt.cxx
@@ -436,9 +436,9 @@ void SwEnvFormatPage::SetMinMax()
     m_pAddrLeftField->SetMax((long) 100 * (lWidth  - 2 * 566), FUNIT_TWIP);
     m_pAddrTopField->SetMin((long) 100 * (GetFieldVal(*m_pSendTopField ) + 2 * 566), FUNIT_TWIP);
     m_pAddrTopField->SetMax((long) 100 * (lHeight - 2 * 566), FUNIT_TWIP);
-    m_pSendLeftField->SetMin((long) 100 * (566), FUNIT_TWIP);
+    m_pSendLeftField->SetMin((long) 100 * 566, FUNIT_TWIP);
     m_pSendLeftField->SetMax((long) 100 * (GetFieldVal(*m_pAddrLeftField) - 566), FUNIT_TWIP);
-    m_pSendTopField->SetMin((long) 100 * (566), FUNIT_TWIP);
+    m_pSendTopField->SetMin((long) 100 * 566, FUNIT_TWIP);
     m_pSendTopField->SetMax((long) 100 * (GetFieldVal(*m_pAddrTopField ) - 2 * 566), FUNIT_TWIP);
 
     // First and last
diff --git a/sw/source/uibase/config/caption.cxx b/sw/source/uibase/config/caption.cxx
index 97244660f550..0458826a30d7 100644
--- a/sw/source/uibase/config/caption.cxx
+++ b/sw/source/uibase/config/caption.cxx
@@ -25,7 +25,7 @@ InsCaptionOpt::InsCaptionOpt(const SwCapObjType eType, const SvGlobalName* pOleI
     bUseCaption(false),
     eObjType(eType),
     nNumType(SVX_NUM_ARABIC),
-    sNumberSeparator((". ")),
+    sNumberSeparator(". "),
     nPos(1),
     nLevel(0),
     sSeparator( OUString(": ") ),
diff --git a/unodevtools/source/skeletonmaker/skeletonmaker.cxx b/unodevtools/source/skeletonmaker/skeletonmaker.cxx
index 091b9357d80f..5ddaf8ee1d4f 100644
--- a/unodevtools/source/skeletonmaker/skeletonmaker.cxx
+++ b/unodevtools/source/skeletonmaker/skeletonmaker.cxx
@@ -254,7 +254,7 @@ SAL_IMPLEMENT_MAIN()
 
     if ( types.empty() && options.componenttype != 3) {
         std::cerr
-            << ("\nError: no type is specified, use the -T option at least once\n");
+            << "\nError: no type is specified, use the -T option at least once\n";
         printUsageAndExit(programname, version);
         exit(EXIT_FAILURE);
     }
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index 1d93f7730aae..25c6c5201902 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -529,7 +529,7 @@ long OutputDevice::ImplGetTextLines( ImplMultiTextLineInfo& rLineInfo,
                                     bool bAlternate = xHyphWord->isAlternativeSpelling();
                                     sal_Int32 _nWordLen = 1 + xHyphWord->getHyphenPos();
 
-                                    if ( ( _nWordLen >= 2 ) && ( (nWordStart+_nWordLen) >= ( 2 ) ) )
+                                    if ( ( _nWordLen >= 2 ) && ( (nWordStart+_nWordLen) >= 2 ) )
                                     {
                                         if ( !bAlternate )
                                         {
diff --git a/xmlsecurity/source/framework/saxeventkeeperimpl.cxx b/xmlsecurity/source/framework/saxeventkeeperimpl.cxx
index c1855ecd31ca..f082b452bad0 100644
--- a/xmlsecurity/source/framework/saxeventkeeperimpl.cxx
+++ b/xmlsecurity/source/framework/saxeventkeeperimpl.cxx
@@ -445,7 +445,7 @@ void SAXEventKeeperImpl::smashBufferNode(
                  */
                 m_xXMLDocument->clearUselessData(m_pRootBufferNode->getXMLElement(),
                     aChildElements,
-                    bIsNotBlocking?(nullptr):
+                    bIsNotBlocking?nullptr:
                                    (m_pCurrentBlockingBufferNode->getXMLElement()));
 
                 /*
@@ -497,7 +497,7 @@ void SAXEventKeeperImpl::smashBufferNode(
                 m_xXMLDocument->clearUselessData(pBufferNode->getXMLElement(),
                     aChildElements,
                     bIsBlockInside?(m_pCurrentBlockingBufferNode->getXMLElement()):
-                               (nullptr));
+                               nullptr);
 
                 /*
                  * remove the node if it is empty, then if its parent is also


More information about the Libreoffice-commits mailing list