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:
committed by
Christian Lohmaier
parent
b35232bdf5
commit
c096ab87c8
@@ -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: */
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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&);
|
||||
};
|
||||
|
||||
|
@@ -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]}}
|
||||
};
|
||||
|
||||
|
@@ -11,10 +11,9 @@
|
||||
|
||||
extern int n0;
|
||||
|
||||
namespace N {
|
||||
|
||||
namespace N
|
||||
{
|
||||
extern int v1;
|
||||
|
||||
}
|
||||
|
||||
struct S;
|
||||
|
@@ -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: */
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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: */
|
||||
|
@@ -1565,7 +1565,6 @@ compilerplugins/clang/dodgyswitch.cxx
|
||||
compilerplugins/clang/dyncastvisibility.cxx
|
||||
compilerplugins/clang/dynexcspec.cxx
|
||||
compilerplugins/clang/expandablemethods.cxx
|
||||
compilerplugins/clang/expressionalwayszero.cxx
|
||||
compilerplugins/clang/externandnotdefined.cxx
|
||||
compilerplugins/clang/faileddyncast.cxx
|
||||
compilerplugins/clang/fakebool.cxx
|
||||
@@ -1620,7 +1619,6 @@ compilerplugins/clang/store/bodynotinblock.cxx
|
||||
compilerplugins/clang/store/bodynotinblock.hxx
|
||||
compilerplugins/clang/store/cascadingassignop.cxx
|
||||
compilerplugins/clang/store/cascadingassignop.hxx
|
||||
compilerplugins/clang/store/cascadingcondop.cxx
|
||||
compilerplugins/clang/store/cascadingcondop.hxx
|
||||
compilerplugins/clang/store/changefunctioncalls.cxx
|
||||
compilerplugins/clang/store/constantfunction.cxx
|
||||
@@ -1647,7 +1645,6 @@ compilerplugins/clang/store/sfxitemsetrewrite.cxx
|
||||
compilerplugins/clang/store/stdexception.cxx
|
||||
compilerplugins/clang/store/stylepolice.cxx
|
||||
compilerplugins/clang/store/svstreamoutputoperators.cxx
|
||||
compilerplugins/clang/store/test/deadclass.cxx
|
||||
compilerplugins/clang/store/tutorial/tutorial1.cxx
|
||||
compilerplugins/clang/store/tutorial/tutorial1.hxx
|
||||
compilerplugins/clang/store/tutorial/tutorial1_example.cxx
|
||||
@@ -1671,10 +1668,8 @@ compilerplugins/clang/test/constmethod.cxx
|
||||
compilerplugins/clang/test/constparams.cxx
|
||||
compilerplugins/clang/test/cppunitassertequals.cxx
|
||||
compilerplugins/clang/test/cppunitassertequals.hxx
|
||||
compilerplugins/clang/test/datamembershadow.cxx
|
||||
compilerplugins/clang/test/dodgyswitch.cxx
|
||||
compilerplugins/clang/test/expressionalwayszero.cxx
|
||||
compilerplugins/clang/test/external.hxx
|
||||
compilerplugins/clang/test/faileddyncast.cxx
|
||||
compilerplugins/clang/test/fakebool.cxx
|
||||
compilerplugins/clang/test/finalprotected.cxx
|
||||
@@ -1683,18 +1678,15 @@ compilerplugins/clang/test/indentation.cxx
|
||||
compilerplugins/clang/test/loopvartoosmall.cxx
|
||||
compilerplugins/clang/test/namespaceindentation.cxx
|
||||
compilerplugins/clang/test/oncevar.cxx
|
||||
compilerplugins/clang/test/oslendian-1.cxx
|
||||
compilerplugins/clang/test/oslendian-2.cxx
|
||||
compilerplugins/clang/test/oslendian-3.cxx
|
||||
compilerplugins/clang/test/passparamsbyref.cxx
|
||||
compilerplugins/clang/test/passstuffbyref.cxx
|
||||
compilerplugins/clang/test/redundantcast.cxx
|
||||
compilerplugins/clang/test/redundantcast.hxx
|
||||
compilerplugins/clang/test/redundantinline.cxx
|
||||
compilerplugins/clang/test/redundantinline.hxx
|
||||
compilerplugins/clang/test/redundantpointerops.cxx
|
||||
compilerplugins/clang/test/salunicodeliteral.cxx
|
||||
compilerplugins/clang/test/stringconcatauto.cxx
|
||||
compilerplugins/clang/test/stringconstant.cxx
|
||||
compilerplugins/clang/test/unnecessarycatchthrow.cxx
|
||||
compilerplugins/clang/test/unnecessaryoverride-dtor.cxx
|
||||
|
Reference in New Issue
Block a user