diff options
author | Philipp Hofer <philipp.hofer@protonmail.com> | 2020-11-12 12:51:50 +0100 |
---|---|---|
committer | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2020-11-22 01:56:05 +0100 |
commit | c096ab87c8a11e8d75dc689ea7024288419cfd22 (patch) | |
tree | cbf5e56d19dcb3fd3e68db3688f88d985c950a80 /compilerplugins | |
parent | b35232bdf56fbda34476cf537d53bbea31235a95 (diff) |
tdf#123936 Formatting files in module compilerplugins with clang-format
Change-Id: Ie6e23d3d2a20849e47d048b439d72fd7376c53db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105654
Tested-by: Jenkins
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/expressionalwayszero.cxx | 54 | ||||
-rw-r--r-- | compilerplugins/clang/store/cascadingcondop.cxx | 25 | ||||
-rw-r--r-- | compilerplugins/clang/store/test/deadclass.cxx | 3 | ||||
-rw-r--r-- | compilerplugins/clang/test/datamembershadow.cxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/test/external.hxx | 5 | ||||
-rw-r--r-- | compilerplugins/clang/test/oslendian-1.cxx | 12 | ||||
-rw-r--r-- | compilerplugins/clang/test/redundantcast.hxx | 11 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringconcatauto.cxx | 34 |
8 files changed, 72 insertions, 78 deletions
diff --git a/compilerplugins/clang/expressionalwayszero.cxx b/compilerplugins/clang/expressionalwayszero.cxx index 067aa9cc6dbd..24e7287615ba 100644 --- a/compilerplugins/clang/expressionalwayszero.cxx +++ b/compilerplugins/clang/expressionalwayszero.cxx @@ -21,13 +21,15 @@ Generally a mistake when people meant to use | or operator| */ -namespace { - -class ExpressionAlwaysZero: - public loplugin::FilteringPlugin<ExpressionAlwaysZero> +namespace +{ +class ExpressionAlwaysZero : public loplugin::FilteringPlugin<ExpressionAlwaysZero> { public: - explicit ExpressionAlwaysZero(loplugin::InstantiationData const & data): FilteringPlugin(data) {} + explicit ExpressionAlwaysZero(loplugin::InstantiationData const& data) + : FilteringPlugin(data) + { + } virtual void run() override { @@ -57,15 +59,16 @@ public: TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } - bool VisitBinaryOperator(BinaryOperator const *); - bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const *); - bool TraverseStaticAssertDecl(StaticAssertDecl *); + bool VisitBinaryOperator(BinaryOperator const*); + bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const*); + bool TraverseStaticAssertDecl(StaticAssertDecl*); + private: // note, abusing std::unique_ptr as a std::optional lookalike std::unique_ptr<APSInt> getExprValue(const Expr* arg); }; -bool ExpressionAlwaysZero::VisitBinaryOperator( BinaryOperator const * binaryOperator ) +bool ExpressionAlwaysZero::VisitBinaryOperator(BinaryOperator const* binaryOperator) { if (ignoreLocation(binaryOperator)) return true; @@ -86,16 +89,14 @@ bool ExpressionAlwaysZero::VisitBinaryOperator( BinaryOperator const * binaryOpe ; // ok else return true; - report( - DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1", - compat::getBeginLoc(binaryOperator)) + report(DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1", + compat::getBeginLoc(binaryOperator)) << (lhsValue ? lhsValue->toString(10) : "unknown") - << (rhsValue ? rhsValue->toString(10) : "unknown") - << binaryOperator->getSourceRange(); + << (rhsValue ? rhsValue->toString(10) : "unknown") << binaryOperator->getSourceRange(); return true; } -bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr( CXXOperatorCallExpr const * cxxOperatorCallExpr ) +bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOperatorCallExpr) { if (ignoreLocation(cxxOperatorCallExpr)) return true; @@ -103,7 +104,7 @@ bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr( CXXOperatorCallExpr const * return true; auto op = cxxOperatorCallExpr->getOperator(); - if ( !(op == OO_Amp || op == OO_AmpEqual || op == OO_AmpAmp)) + if (!(op == OO_Amp || op == OO_AmpEqual || op == OO_AmpAmp)) return true; if (cxxOperatorCallExpr->getNumArgs() != 2) @@ -118,20 +119,19 @@ bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr( CXXOperatorCallExpr const * ; // ok else return true; - report( - DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1", - compat::getBeginLoc(cxxOperatorCallExpr)) + report(DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1", + compat::getBeginLoc(cxxOperatorCallExpr)) << (lhsValue ? lhsValue->toString(10) : "unknown") - << (rhsValue ? rhsValue->toString(10) : "unknown") - << cxxOperatorCallExpr->getSourceRange(); + << (rhsValue ? rhsValue->toString(10) : "unknown") << cxxOperatorCallExpr->getSourceRange(); return true; } -std::unique_ptr<APSInt> ExpressionAlwaysZero::getExprValue(Expr const * expr) +std::unique_ptr<APSInt> ExpressionAlwaysZero::getExprValue(Expr const* expr) { expr = expr->IgnoreParenCasts(); // ignore this, it seems to trigger an infinite recursion - if (isa<UnaryExprOrTypeTraitExpr>(expr)) { + if (isa<UnaryExprOrTypeTraitExpr>(expr)) + { return std::unique_ptr<APSInt>(); } APSInt x1; @@ -141,13 +141,9 @@ std::unique_ptr<APSInt> ExpressionAlwaysZero::getExprValue(Expr const * expr) } // these will often evaluate to zero harmlessly -bool ExpressionAlwaysZero::TraverseStaticAssertDecl( StaticAssertDecl * ) -{ - return true; -} - -loplugin::Plugin::Registration< ExpressionAlwaysZero > X("expressionalwayszero", false); +bool ExpressionAlwaysZero::TraverseStaticAssertDecl(StaticAssertDecl*) { return true; } +loplugin::Plugin::Registration<ExpressionAlwaysZero> X("expressionalwayszero", false); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/store/cascadingcondop.cxx b/compilerplugins/clang/store/cascadingcondop.cxx index f2687e76922d..4671f41b436a 100644 --- a/compilerplugins/clang/store/cascadingcondop.cxx +++ b/compilerplugins/clang/store/cascadingcondop.cxx @@ -30,16 +30,15 @@ static const int stmtlimit = 50; namespace loplugin { - struct WalkCounter { - int stmtcount; + int stmtcount; bool cascading; }; // Ctor, nothing special, pass the argument(s). -CascadingCondOp::CascadingCondOp( const InstantiationData& data ) - : FilteringPlugin( data ) +CascadingCondOp::CascadingCondOp(const InstantiationData& data) + : FilteringPlugin(data) { } @@ -48,38 +47,38 @@ void CascadingCondOp::run() { // Traverse the whole AST of the translation unit (i.e. examine the whole source file). // The Clang AST helper class will call VisitReturnStmt for every return statement. - TraverseDecl( compiler.getASTContext().getTranslationUnitDecl()); + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } -void CascadingCondOp::Walk( const Stmt* stmt, WalkCounter& c ) +void CascadingCondOp::Walk(const Stmt* stmt, WalkCounter& c) { - for(Stmt::const_child_iterator it = stmt->child_begin(); it != stmt->child_end(); ++it) + for (Stmt::const_child_iterator it = stmt->child_begin(); it != stmt->child_end(); ++it) { ++c.stmtcount; - if ( dyn_cast< ConditionalOperator >( *it )) + if (dyn_cast<ConditionalOperator>(*it)) c.cascading = true; Walk(*it, c); } } -bool CascadingCondOp::VisitStmt( const Stmt* stmt ) +bool CascadingCondOp::VisitStmt(const Stmt* stmt) { - if ( const ConditionalOperator* condop = dyn_cast< ConditionalOperator >( stmt )) + if (const ConditionalOperator* condop = dyn_cast<ConditionalOperator>(stmt)) { WalkCounter c = { 0, false }; Walk(condop, c); - if(c.cascading && c.stmtcount >= stmtlimit) + if (c.cascading && c.stmtcount >= stmtlimit) { std::string msg("cascading conditional operator, complexity: "); msg.append(std::to_string(c.stmtcount)); - report( DiagnosticsEngine::Warning, msg, condop->getLocStart()); + report(DiagnosticsEngine::Warning, msg, condop->getLocStart()); } } return true; } // Register the plugin action with the LO plugin handling. -static Plugin::Registration< CascadingCondOp > X( "cascadingcondop" ); +static Plugin::Registration<CascadingCondOp> X("cascadingcondop"); } // namespace loplugin diff --git a/compilerplugins/clang/store/test/deadclass.cxx b/compilerplugins/clang/store/test/deadclass.cxx index d8b9cdb60889..ffae241d4285 100644 --- a/compilerplugins/clang/store/test/deadclass.cxx +++ b/compilerplugins/clang/store/test/deadclass.cxx @@ -7,7 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -struct Foo { // expected-error {{class has only copy/move constructors, must be dead [loplugin:deadclass]}} +struct Foo +{ // expected-error {{class has only copy/move constructors, must be dead [loplugin:deadclass]}} Foo(Foo&); }; diff --git a/compilerplugins/clang/test/datamembershadow.cxx b/compilerplugins/clang/test/datamembershadow.cxx index a11a7cc51c65..ef8722d5c806 100644 --- a/compilerplugins/clang/test/datamembershadow.cxx +++ b/compilerplugins/clang/test/datamembershadow.cxx @@ -11,11 +11,13 @@ #include <config_clang.h> -struct Bar { +struct Bar +{ int x; // expected-note {{superclass member here [loplugin:datamembershadow]}} }; -struct Foo : public Bar { +struct Foo : public Bar +{ int x; // expected-error {{data member x is shadowing member in superclass, through inheritance path Foo->Bar [loplugin:datamembershadow]}} }; diff --git a/compilerplugins/clang/test/external.hxx b/compilerplugins/clang/test/external.hxx index 749fec0ee3c7..40e8d55c0afe 100644 --- a/compilerplugins/clang/test/external.hxx +++ b/compilerplugins/clang/test/external.hxx @@ -11,10 +11,9 @@ extern int n0; -namespace N { - +namespace N +{ extern int v1; - } struct S; diff --git a/compilerplugins/clang/test/oslendian-1.cxx b/compilerplugins/clang/test/oslendian-1.cxx index 7349239aa98d..7d0023037f75 100644 --- a/compilerplugins/clang/test/oslendian-1.cxx +++ b/compilerplugins/clang/test/oslendian-1.cxx @@ -24,24 +24,24 @@ #if !defined OSL_BIGENDIAN #define OSL_BIGENDIAN - // expected-error@-1 {{macro 'OSL_BIGENDIAN' defined in addition to 'OSL_LITENDIAN' [loplugin:oslendian]}} - // expected-note@osl/endian.h:* {{conflicting macro definition is here [loplugin:oslendian]}} +// expected-error@-1 {{macro 'OSL_BIGENDIAN' defined in addition to 'OSL_LITENDIAN' [loplugin:oslendian]}} +// expected-note@osl/endian.h:* {{conflicting macro definition is here [loplugin:oslendian]}} #endif #if !defined OSL_LITENDIAN #define OSL_LITENDIAN - // expected-error@-1 {{macro 'OSL_LITENDIAN' defined in addition to 'OSL_BIGENDIAN' [loplugin:oslendian]}} - // expected-note@osl/endian.h:* {{conflicting macro definition is here [loplugin:oslendian]}} +// expected-error@-1 {{macro 'OSL_LITENDIAN' defined in addition to 'OSL_BIGENDIAN' [loplugin:oslendian]}} +// expected-note@osl/endian.h:* {{conflicting macro definition is here [loplugin:oslendian]}} #endif #if defined OSL_BIGENDIAN #undef OSL_BIGENDIAN - // expected-error@-1 {{macro 'OSL_BIGENDIAN' undefinition [loplugin:oslendian]}} +// expected-error@-1 {{macro 'OSL_BIGENDIAN' undefinition [loplugin:oslendian]}} #endif #if defined OSL_LITENDIAN #undef OSL_LITENDIAN - // expected-error@-1 {{macro 'OSL_LITENDIAN' undefinition [loplugin:oslendian]}} +// expected-error@-1 {{macro 'OSL_LITENDIAN' undefinition [loplugin:oslendian]}} #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/test/redundantcast.hxx b/compilerplugins/clang/test/redundantcast.hxx index 113dd0f1a8e8..0afab0c2dc07 100644 --- a/compilerplugins/clang/test/redundantcast.hxx +++ b/compilerplugins/clang/test/redundantcast.hxx @@ -9,23 +9,24 @@ #pragma once -struct S { +struct S +{ void f1(); void f2() const; void f3(); void f3() const; }; -int && nix(); -int const && cix(); +int&& nix(); +int const&& cix(); int nir(); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wignored-qualifiers" int const cir(); #pragma clang diagnostic pop -S && nsx(); -S const && csx(); +S&& nsx(); +S const&& csx(); S nsr(); S const csr(); diff --git a/compilerplugins/clang/test/stringconcatauto.cxx b/compilerplugins/clang/test/stringconcatauto.cxx index 6c9a72c293b3..8318e3c4a26f 100644 --- a/compilerplugins/clang/test/stringconcatauto.cxx +++ b/compilerplugins/clang/test/stringconcatauto.cxx @@ -13,24 +13,24 @@ void foo() { - auto str1 = "str1" + OUString::number( 10 ); + auto str1 = "str1" + OUString::number(10); // expected-error-re@-1 {{creating a variable of type 'rtl::OUStringConcat<{{.*}}>' will make it reference temporaries}} // expected-note@-2 {{use OUString instead}} - OUString str2 = "str2" + OUString::number( 20 ) + "ing"; - const auto& str3 = "str3" + OUString::number( 30 ); + OUString str2 = "str2" + OUString::number(20) + "ing"; + const auto& str3 = "str3" + OUString::number(30); // expected-error-re@-1 {{creating a variable of type 'const rtl::OUStringConcat<{{.*}}> &' will make it reference temporaries}} // expected-note@-2 {{use OUString instead}} - const auto str4 = "str4" + OString::number( 40 ); + const auto str4 = "str4" + OString::number(40); // expected-error-re@-1 {{creating a variable of type 'const rtl::OStringConcat<{{.*}}>' will make it reference temporaries}} // expected-note@-2 {{use OString instead}} - auto str5 = OUString::number( 50 ); + auto str5 = OUString::number(50); // expected-error-re@-1 {{creating a variable of type 'rtl::OUStringNumber<{{.*}}>' will make it reference temporaries}} // expected-note@-2 {{use OUString instead}} - (void) str1; - (void) str2; - (void) str3; - (void) str4; - (void) str5; + (void)str1; + (void)str2; + (void)str3; + (void)str4; + (void)str5; } struct A @@ -39,29 +39,25 @@ struct A // expected-error-re@-1 {{returning a variable of type 'rtl::OStringConcat<{{.*}}>' will make it reference temporaries}} // expected-note@-2 {{use OString instead}} { - return "bar" + OString::number( 110 ); + return "bar" + OString::number(110); } auto baz() // expected-error-re@-1 {{returning a variable of type 'rtl::OStringNumber<{{.*}}>' will make it reference temporaries}} // expected-note@-2 {{use OString instead}} { - return OString::number( 120 ); + return OString::number(120); } }; -template< typename T > -void fun( const T& par ) +template <typename T> void fun(const T& par) // parameters are without warnings { const T& var = par; // expected-error-re@-1 {{creating a variable of type 'const rtl::OUStringConcat<{{.*}}> &' will make it reference temporaries}} // expected-note@-2 {{use OUString instead}} - (void) var; + (void)var; } -void testfun() -{ - fun( "fun" + OUString::number( 200 )); -} +void testfun() { fun("fun" + OUString::number(200)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |