rename redundantcopy loplugin to redundantfcast

Change-Id: I34e28a30a4f1fd264c18c901cd94094531543271
This commit is contained in:
Noel Grandin
2018-02-22 08:55:08 +02:00
parent 38604d6cbe
commit 50d0ec571f
4 changed files with 69 additions and 60 deletions

View File

@@ -11,50 +11,51 @@
#include "compat.hxx" #include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
namespace { namespace
{
class RedundantCopy final: class RedundantFCast final : public RecursiveASTVisitor<RedundantFCast>, public loplugin::Plugin
public RecursiveASTVisitor<RedundantCopy>, public loplugin::Plugin
{ {
public: public:
explicit RedundantCopy(loplugin::InstantiationData const & data): explicit RedundantFCast(loplugin::InstantiationData const& data)
Plugin(data) {} : Plugin(data)
{
}
bool VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * expr) { bool VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const* expr)
if (ignoreLocation(expr)) { {
if (ignoreLocation(expr))
{
return true; return true;
} }
auto const t1 = expr->getTypeAsWritten(); auto const t1 = expr->getTypeAsWritten();
auto const t2 = compat::getSubExprAsWritten(expr)->getType(); auto const t2 = compat::getSubExprAsWritten(expr)->getType();
if (t1.getCanonicalType().getTypePtr() if (t1.getCanonicalType().getTypePtr() != t2.getCanonicalType().getTypePtr())
!= t2.getCanonicalType().getTypePtr())
{ {
return true; return true;
} }
auto tc = loplugin::TypeCheck(t1); auto tc = loplugin::TypeCheck(t1);
if (!(tc.Class("OUString").Namespace("rtl").GlobalNamespace() if (!(tc.Class("OUString").Namespace("rtl").GlobalNamespace()
|| tc.Class("Color").GlobalNamespace() || tc.Class("Color").GlobalNamespace() || tc.Class("unique_ptr").StdNamespace()))
|| tc.Class("unique_ptr").StdNamespace()))
{ {
return true; return true;
} }
report( report(DiagnosticsEngine::Warning, "redundant functional cast from %0 to %1",
DiagnosticsEngine::Warning, expr->getExprLoc())
"redundant copy construction from %0 to %1", expr->getExprLoc())
<< t2 << t1 << expr->getSourceRange(); << t2 << t1 << expr->getSourceRange();
return true; return true;
} }
private: private:
void run() override { void run() override
if (compiler.getLangOpts().CPlusPlus) { {
if (compiler.getLangOpts().CPlusPlus)
{
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
} }
} }
}; };
static loplugin::Plugin::Registration<RedundantCopy> reg("redundantcopy"); static loplugin::Plugin::Registration<RedundantFCast> reg("redundantfcast");
} }
/* 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

@@ -1,40 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "sal/config.h"
#include <memory>
#include "rtl/ustring.hxx"
#include "tools/color.hxx"
void method1(OUString const &);
int main() {
OUString s;
(void) OUString(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantcopy]}}
using T1 = OUString;
(void) T1(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'T1' (aka 'rtl::OUString') [loplugin:redundantcopy]}}
using T2 = OUString const;
(void) T2(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'T2' (aka 'const rtl::OUString') [loplugin:redundantcopy]}}
(void) std::unique_ptr<int>(std::unique_ptr<int>(new int{})); // expected-error {{redundant copy construction from 'std::unique_ptr<int>' to 'std::unique_ptr<int>' [loplugin:redundantcopy]}}
OUString s1;
method1( OUString(s1) ); // expected-error {{redundant copy construction from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantcopy]}}
OUString s2;
s2 = OUString(s1); // expected-error {{redundant copy construction from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantcopy]}}
Color col1;
Color col2 = Color(col1); // expected-error {{redundant copy construction from 'Color' to 'Color' [loplugin:redundantcopy]}}
(void)col2;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View File

@@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "sal/config.h"
#include <memory>
#include "rtl/ustring.hxx"
#include "tools/color.hxx"
void method1(OUString const&);
int main()
{
OUString s;
(void)OUString(
s); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantfcast]}}
using T1 = OUString;
(void)T1(
s); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'T1' (aka 'rtl::OUString') [loplugin:redundantfcast]}}
using T2 = OUString const;
(void)T2(
s); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'T2' (aka 'const rtl::OUString') [loplugin:redundantfcast]}}
(void)std::unique_ptr<int>(std::unique_ptr<int>(
new int{})); // expected-error@-1 {{redundant functional cast from 'std::unique_ptr<int>' to 'std::unique_ptr<int>' [loplugin:redundantfcast]}}
OUString s1;
method1(OUString(
s1)); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantfcast]}}
OUString s2;
s2 = OUString(
s1); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantfcast]}}
Color col1;
Color col2 = Color(
col1); // expected-error@-1 {{redundant functional cast from 'Color' to 'Color' [loplugin:redundantfcast]}}
(void)col2;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View File

@@ -35,7 +35,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/passstuffbyref \ compilerplugins/clang/test/passstuffbyref \
compilerplugins/clang/test/pointerbool \ compilerplugins/clang/test/pointerbool \
compilerplugins/clang/test/redundantcast \ compilerplugins/clang/test/redundantcast \
compilerplugins/clang/test/redundantcopy \ compilerplugins/clang/test/redundantfcast \
compilerplugins/clang/test/redundantinline \ compilerplugins/clang/test/redundantinline \
compilerplugins/clang/test/redundantpointerops \ compilerplugins/clang/test/redundantpointerops \
compilerplugins/clang/test/refcounting \ compilerplugins/clang/test/refcounting \