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>
This commit is contained in:
Philipp Hofer
2020-11-12 12:51:50 +01:00
committed by Christian Lohmaier
parent b35232bdf5
commit c096ab87c8
9 changed files with 72 additions and 86 deletions

View File

@@ -21,13 +21,15 @@
Generally a mistake when people meant to use | or operator| Generally a mistake when people meant to use | or operator|
*/ */
namespace { namespace
{
class ExpressionAlwaysZero: class ExpressionAlwaysZero : public loplugin::FilteringPlugin<ExpressionAlwaysZero>
public loplugin::FilteringPlugin<ExpressionAlwaysZero>
{ {
public: public:
explicit ExpressionAlwaysZero(loplugin::InstantiationData const & data): FilteringPlugin(data) {} explicit ExpressionAlwaysZero(loplugin::InstantiationData const& data)
: FilteringPlugin(data)
{
}
virtual void run() override virtual void run() override
{ {
@@ -57,15 +59,16 @@ public:
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
} }
bool VisitBinaryOperator(BinaryOperator const *); bool VisitBinaryOperator(BinaryOperator const*);
bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const *); bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const*);
bool TraverseStaticAssertDecl(StaticAssertDecl *); bool TraverseStaticAssertDecl(StaticAssertDecl*);
private: private:
// note, abusing std::unique_ptr as a std::optional lookalike // note, abusing std::unique_ptr as a std::optional lookalike
std::unique_ptr<APSInt> getExprValue(const Expr* arg); std::unique_ptr<APSInt> getExprValue(const Expr* arg);
}; };
bool ExpressionAlwaysZero::VisitBinaryOperator( BinaryOperator const * binaryOperator ) bool ExpressionAlwaysZero::VisitBinaryOperator(BinaryOperator const* binaryOperator)
{ {
if (ignoreLocation(binaryOperator)) if (ignoreLocation(binaryOperator))
return true; return true;
@@ -86,16 +89,14 @@ bool ExpressionAlwaysZero::VisitBinaryOperator( BinaryOperator const * binaryOpe
; // ok ; // ok
else else
return true; return true;
report( report(DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1",
DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1", compat::getBeginLoc(binaryOperator))
compat::getBeginLoc(binaryOperator))
<< (lhsValue ? lhsValue->toString(10) : "unknown") << (lhsValue ? lhsValue->toString(10) : "unknown")
<< (rhsValue ? rhsValue->toString(10) : "unknown") << (rhsValue ? rhsValue->toString(10) : "unknown") << binaryOperator->getSourceRange();
<< binaryOperator->getSourceRange();
return true; return true;
} }
bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr( CXXOperatorCallExpr const * cxxOperatorCallExpr ) bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOperatorCallExpr)
{ {
if (ignoreLocation(cxxOperatorCallExpr)) if (ignoreLocation(cxxOperatorCallExpr))
return true; return true;
@@ -103,7 +104,7 @@ bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr( CXXOperatorCallExpr const *
return true; return true;
auto op = cxxOperatorCallExpr->getOperator(); 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; return true;
if (cxxOperatorCallExpr->getNumArgs() != 2) if (cxxOperatorCallExpr->getNumArgs() != 2)
@@ -118,20 +119,19 @@ bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr( CXXOperatorCallExpr const *
; // ok ; // ok
else else
return true; return true;
report( report(DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1",
DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1", compat::getBeginLoc(cxxOperatorCallExpr))
compat::getBeginLoc(cxxOperatorCallExpr))
<< (lhsValue ? lhsValue->toString(10) : "unknown") << (lhsValue ? lhsValue->toString(10) : "unknown")
<< (rhsValue ? rhsValue->toString(10) : "unknown") << (rhsValue ? rhsValue->toString(10) : "unknown") << cxxOperatorCallExpr->getSourceRange();
<< cxxOperatorCallExpr->getSourceRange();
return true; return true;
} }
std::unique_ptr<APSInt> ExpressionAlwaysZero::getExprValue(Expr const * expr) std::unique_ptr<APSInt> ExpressionAlwaysZero::getExprValue(Expr const* expr)
{ {
expr = expr->IgnoreParenCasts(); expr = expr->IgnoreParenCasts();
// ignore this, it seems to trigger an infinite recursion // ignore this, it seems to trigger an infinite recursion
if (isa<UnaryExprOrTypeTraitExpr>(expr)) { if (isa<UnaryExprOrTypeTraitExpr>(expr))
{
return std::unique_ptr<APSInt>(); return std::unique_ptr<APSInt>();
} }
APSInt x1; APSInt x1;
@@ -141,13 +141,9 @@ std::unique_ptr<APSInt> ExpressionAlwaysZero::getExprValue(Expr const * expr)
} }
// these will often evaluate to zero harmlessly // these will often evaluate to zero harmlessly
bool ExpressionAlwaysZero::TraverseStaticAssertDecl( StaticAssertDecl * ) bool ExpressionAlwaysZero::TraverseStaticAssertDecl(StaticAssertDecl*) { return true; }
{
return true;
}
loplugin::Plugin::Registration< ExpressionAlwaysZero > X("expressionalwayszero", false);
loplugin::Plugin::Registration<ExpressionAlwaysZero> X("expressionalwayszero", false);
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -30,16 +30,15 @@ static const int stmtlimit = 50;
namespace loplugin namespace loplugin
{ {
struct WalkCounter struct WalkCounter
{ {
int stmtcount; int stmtcount;
bool cascading; bool cascading;
}; };
// Ctor, nothing special, pass the argument(s). // Ctor, nothing special, pass the argument(s).
CascadingCondOp::CascadingCondOp( const InstantiationData& data ) CascadingCondOp::CascadingCondOp(const InstantiationData& data)
: FilteringPlugin( 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). // 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. // 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; ++c.stmtcount;
if ( dyn_cast< ConditionalOperator >( *it )) if (dyn_cast<ConditionalOperator>(*it))
c.cascading = true; c.cascading = true;
Walk(*it, c); 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 }; WalkCounter c = { 0, false };
Walk(condop, c); Walk(condop, c);
if(c.cascading && c.stmtcount >= stmtlimit) if (c.cascading && c.stmtcount >= stmtlimit)
{ {
std::string msg("cascading conditional operator, complexity: "); std::string msg("cascading conditional operator, complexity: ");
msg.append(std::to_string(c.stmtcount)); msg.append(std::to_string(c.stmtcount));
report( DiagnosticsEngine::Warning, msg, condop->getLocStart()); report(DiagnosticsEngine::Warning, msg, condop->getLocStart());
} }
} }
return true; return true;
} }
// Register the plugin action with the LO plugin handling. // Register the plugin action with the LO plugin handling.
static Plugin::Registration< CascadingCondOp > X( "cascadingcondop" ); static Plugin::Registration<CascadingCondOp> X("cascadingcondop");
} // namespace loplugin } // namespace loplugin

View File

@@ -7,7 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * 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&); Foo(Foo&);
}; };

View File

@@ -11,11 +11,13 @@
#include <config_clang.h> #include <config_clang.h>
struct Bar { struct Bar
{
int x; // expected-note {{superclass member here [loplugin:datamembershadow]}} 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]}} int x; // expected-error {{data member x is shadowing member in superclass, through inheritance path Foo->Bar [loplugin:datamembershadow]}}
}; };

View File

@@ -11,10 +11,9 @@
extern int n0; extern int n0;
namespace N { namespace N
{
extern int v1; extern int v1;
} }
struct S; struct S;

View File

@@ -24,24 +24,24 @@
#if !defined OSL_BIGENDIAN #if !defined OSL_BIGENDIAN
#define OSL_BIGENDIAN #define OSL_BIGENDIAN
// expected-error@-1 {{macro 'OSL_BIGENDIAN' defined in addition to 'OSL_LITENDIAN' [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]}} // expected-note@osl/endian.h:* {{conflicting macro definition is here [loplugin:oslendian]}}
#endif #endif
#if !defined OSL_LITENDIAN #if !defined OSL_LITENDIAN
#define OSL_LITENDIAN #define OSL_LITENDIAN
// expected-error@-1 {{macro 'OSL_LITENDIAN' defined in addition to 'OSL_BIGENDIAN' [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]}} // expected-note@osl/endian.h:* {{conflicting macro definition is here [loplugin:oslendian]}}
#endif #endif
#if defined OSL_BIGENDIAN #if defined OSL_BIGENDIAN
#undef OSL_BIGENDIAN #undef OSL_BIGENDIAN
// expected-error@-1 {{macro 'OSL_BIGENDIAN' undefinition [loplugin:oslendian]}} // expected-error@-1 {{macro 'OSL_BIGENDIAN' undefinition [loplugin:oslendian]}}
#endif #endif
#if defined OSL_LITENDIAN #if defined OSL_LITENDIAN
#undef OSL_LITENDIAN #undef OSL_LITENDIAN
// expected-error@-1 {{macro 'OSL_LITENDIAN' undefinition [loplugin:oslendian]}} // expected-error@-1 {{macro 'OSL_LITENDIAN' undefinition [loplugin:oslendian]}}
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View File

@@ -9,23 +9,24 @@
#pragma once #pragma once
struct S { struct S
{
void f1(); void f1();
void f2() const; void f2() const;
void f3(); void f3();
void f3() const; void f3() const;
}; };
int && nix(); int&& nix();
int const && cix(); int const&& cix();
int nir(); int nir();
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wignored-qualifiers" #pragma clang diagnostic ignored "-Wignored-qualifiers"
int const cir(); int const cir();
#pragma clang diagnostic pop #pragma clang diagnostic pop
S && nsx(); S&& nsx();
S const && csx(); S const&& csx();
S nsr(); S nsr();
S const csr(); S const csr();

View File

@@ -13,24 +13,24 @@
void foo() 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-error-re@-1 {{creating a variable of type 'rtl::OUStringConcat<{{.*}}>' will make it reference temporaries}}
// expected-note@-2 {{use OUString instead}} // expected-note@-2 {{use OUString instead}}
OUString str2 = "str2" + OUString::number( 20 ) + "ing"; OUString str2 = "str2" + OUString::number(20) + "ing";
const auto& str3 = "str3" + OUString::number( 30 ); 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-error-re@-1 {{creating a variable of type 'const rtl::OUStringConcat<{{.*}}> &' will make it reference temporaries}}
// expected-note@-2 {{use OUString instead}} // 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-error-re@-1 {{creating a variable of type 'const rtl::OStringConcat<{{.*}}>' will make it reference temporaries}}
// expected-note@-2 {{use OString instead}} // 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-error-re@-1 {{creating a variable of type 'rtl::OUStringNumber<{{.*}}>' will make it reference temporaries}}
// expected-note@-2 {{use OUString instead}} // expected-note@-2 {{use OUString instead}}
(void) str1; (void)str1;
(void) str2; (void)str2;
(void) str3; (void)str3;
(void) str4; (void)str4;
(void) str5; (void)str5;
} }
struct A 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-error-re@-1 {{returning a variable of type 'rtl::OStringConcat<{{.*}}>' will make it reference temporaries}}
// expected-note@-2 {{use OString instead}} // expected-note@-2 {{use OString instead}}
{ {
return "bar" + OString::number( 110 ); return "bar" + OString::number(110);
} }
auto baz() auto baz()
// expected-error-re@-1 {{returning a variable of type 'rtl::OStringNumber<{{.*}}>' will make it reference temporaries}} // expected-error-re@-1 {{returning a variable of type 'rtl::OStringNumber<{{.*}}>' will make it reference temporaries}}
// expected-note@-2 {{use OString instead}} // expected-note@-2 {{use OString instead}}
{ {
return OString::number( 120 ); return OString::number(120);
} }
}; };
template< typename T > template <typename T> void fun(const T& par)
void fun( const T& par )
// parameters are without warnings // parameters are without warnings
{ {
const T& var = par; const T& var = par;
// expected-error-re@-1 {{creating a variable of type 'const rtl::OUStringConcat<{{.*}}> &' will make it reference temporaries}} // expected-error-re@-1 {{creating a variable of type 'const rtl::OUStringConcat<{{.*}}> &' will make it reference temporaries}}
// expected-note@-2 {{use OUString instead}} // expected-note@-2 {{use OUString instead}}
(void) var; (void)var;
} }
void testfun() void testfun() { fun("fun" + OUString::number(200)); }
{
fun( "fun" + OUString::number( 200 ));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -1565,7 +1565,6 @@ compilerplugins/clang/dodgyswitch.cxx
compilerplugins/clang/dyncastvisibility.cxx compilerplugins/clang/dyncastvisibility.cxx
compilerplugins/clang/dynexcspec.cxx compilerplugins/clang/dynexcspec.cxx
compilerplugins/clang/expandablemethods.cxx compilerplugins/clang/expandablemethods.cxx
compilerplugins/clang/expressionalwayszero.cxx
compilerplugins/clang/externandnotdefined.cxx compilerplugins/clang/externandnotdefined.cxx
compilerplugins/clang/faileddyncast.cxx compilerplugins/clang/faileddyncast.cxx
compilerplugins/clang/fakebool.cxx compilerplugins/clang/fakebool.cxx
@@ -1620,7 +1619,6 @@ compilerplugins/clang/store/bodynotinblock.cxx
compilerplugins/clang/store/bodynotinblock.hxx compilerplugins/clang/store/bodynotinblock.hxx
compilerplugins/clang/store/cascadingassignop.cxx compilerplugins/clang/store/cascadingassignop.cxx
compilerplugins/clang/store/cascadingassignop.hxx compilerplugins/clang/store/cascadingassignop.hxx
compilerplugins/clang/store/cascadingcondop.cxx
compilerplugins/clang/store/cascadingcondop.hxx compilerplugins/clang/store/cascadingcondop.hxx
compilerplugins/clang/store/changefunctioncalls.cxx compilerplugins/clang/store/changefunctioncalls.cxx
compilerplugins/clang/store/constantfunction.cxx compilerplugins/clang/store/constantfunction.cxx
@@ -1647,7 +1645,6 @@ compilerplugins/clang/store/sfxitemsetrewrite.cxx
compilerplugins/clang/store/stdexception.cxx compilerplugins/clang/store/stdexception.cxx
compilerplugins/clang/store/stylepolice.cxx compilerplugins/clang/store/stylepolice.cxx
compilerplugins/clang/store/svstreamoutputoperators.cxx compilerplugins/clang/store/svstreamoutputoperators.cxx
compilerplugins/clang/store/test/deadclass.cxx
compilerplugins/clang/store/tutorial/tutorial1.cxx compilerplugins/clang/store/tutorial/tutorial1.cxx
compilerplugins/clang/store/tutorial/tutorial1.hxx compilerplugins/clang/store/tutorial/tutorial1.hxx
compilerplugins/clang/store/tutorial/tutorial1_example.cxx compilerplugins/clang/store/tutorial/tutorial1_example.cxx
@@ -1671,10 +1668,8 @@ compilerplugins/clang/test/constmethod.cxx
compilerplugins/clang/test/constparams.cxx compilerplugins/clang/test/constparams.cxx
compilerplugins/clang/test/cppunitassertequals.cxx compilerplugins/clang/test/cppunitassertequals.cxx
compilerplugins/clang/test/cppunitassertequals.hxx compilerplugins/clang/test/cppunitassertequals.hxx
compilerplugins/clang/test/datamembershadow.cxx
compilerplugins/clang/test/dodgyswitch.cxx compilerplugins/clang/test/dodgyswitch.cxx
compilerplugins/clang/test/expressionalwayszero.cxx compilerplugins/clang/test/expressionalwayszero.cxx
compilerplugins/clang/test/external.hxx
compilerplugins/clang/test/faileddyncast.cxx compilerplugins/clang/test/faileddyncast.cxx
compilerplugins/clang/test/fakebool.cxx compilerplugins/clang/test/fakebool.cxx
compilerplugins/clang/test/finalprotected.cxx compilerplugins/clang/test/finalprotected.cxx
@@ -1683,18 +1678,15 @@ compilerplugins/clang/test/indentation.cxx
compilerplugins/clang/test/loopvartoosmall.cxx compilerplugins/clang/test/loopvartoosmall.cxx
compilerplugins/clang/test/namespaceindentation.cxx compilerplugins/clang/test/namespaceindentation.cxx
compilerplugins/clang/test/oncevar.cxx compilerplugins/clang/test/oncevar.cxx
compilerplugins/clang/test/oslendian-1.cxx
compilerplugins/clang/test/oslendian-2.cxx compilerplugins/clang/test/oslendian-2.cxx
compilerplugins/clang/test/oslendian-3.cxx compilerplugins/clang/test/oslendian-3.cxx
compilerplugins/clang/test/passparamsbyref.cxx compilerplugins/clang/test/passparamsbyref.cxx
compilerplugins/clang/test/passstuffbyref.cxx compilerplugins/clang/test/passstuffbyref.cxx
compilerplugins/clang/test/redundantcast.cxx compilerplugins/clang/test/redundantcast.cxx
compilerplugins/clang/test/redundantcast.hxx
compilerplugins/clang/test/redundantinline.cxx compilerplugins/clang/test/redundantinline.cxx
compilerplugins/clang/test/redundantinline.hxx compilerplugins/clang/test/redundantinline.hxx
compilerplugins/clang/test/redundantpointerops.cxx compilerplugins/clang/test/redundantpointerops.cxx
compilerplugins/clang/test/salunicodeliteral.cxx compilerplugins/clang/test/salunicodeliteral.cxx
compilerplugins/clang/test/stringconcatauto.cxx
compilerplugins/clang/test/stringconstant.cxx compilerplugins/clang/test/stringconstant.cxx
compilerplugins/clang/test/unnecessarycatchthrow.cxx compilerplugins/clang/test/unnecessarycatchthrow.cxx
compilerplugins/clang/test/unnecessaryoverride-dtor.cxx compilerplugins/clang/test/unnecessaryoverride-dtor.cxx