rename redundantcopy loplugin to redundantfcast
Change-Id: I34e28a30a4f1fd264c18c901cd94094531543271
This commit is contained in:
@@ -11,50 +11,51 @@
|
||||
#include "compat.hxx"
|
||||
#include "plugin.hxx"
|
||||
|
||||
namespace {
|
||||
|
||||
class RedundantCopy final:
|
||||
public RecursiveASTVisitor<RedundantCopy>, public loplugin::Plugin
|
||||
namespace
|
||||
{
|
||||
class RedundantFCast final : public RecursiveASTVisitor<RedundantFCast>, public loplugin::Plugin
|
||||
{
|
||||
public:
|
||||
explicit RedundantCopy(loplugin::InstantiationData const & data):
|
||||
Plugin(data) {}
|
||||
explicit RedundantFCast(loplugin::InstantiationData const& data)
|
||||
: Plugin(data)
|
||||
{
|
||||
}
|
||||
|
||||
bool VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * expr) {
|
||||
if (ignoreLocation(expr)) {
|
||||
bool VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const* expr)
|
||||
{
|
||||
if (ignoreLocation(expr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
auto const t1 = expr->getTypeAsWritten();
|
||||
auto const t2 = compat::getSubExprAsWritten(expr)->getType();
|
||||
if (t1.getCanonicalType().getTypePtr()
|
||||
!= t2.getCanonicalType().getTypePtr())
|
||||
if (t1.getCanonicalType().getTypePtr() != t2.getCanonicalType().getTypePtr())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
auto tc = loplugin::TypeCheck(t1);
|
||||
if (!(tc.Class("OUString").Namespace("rtl").GlobalNamespace()
|
||||
|| tc.Class("Color").GlobalNamespace()
|
||||
|| tc.Class("unique_ptr").StdNamespace()))
|
||||
|| tc.Class("Color").GlobalNamespace() || tc.Class("unique_ptr").StdNamespace()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
report(
|
||||
DiagnosticsEngine::Warning,
|
||||
"redundant copy construction from %0 to %1", expr->getExprLoc())
|
||||
report(DiagnosticsEngine::Warning, "redundant functional cast from %0 to %1",
|
||||
expr->getExprLoc())
|
||||
<< t2 << t1 << expr->getSourceRange();
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
void run() override {
|
||||
if (compiler.getLangOpts().CPlusPlus) {
|
||||
void run() override
|
||||
{
|
||||
if (compiler.getLangOpts().CPlusPlus)
|
||||
{
|
||||
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: */
|
@@ -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: */
|
48
compilerplugins/clang/test/redundantfcast.cxx
Normal file
48
compilerplugins/clang/test/redundantfcast.cxx
Normal 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: */
|
@@ -35,7 +35,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
|
||||
compilerplugins/clang/test/passstuffbyref \
|
||||
compilerplugins/clang/test/pointerbool \
|
||||
compilerplugins/clang/test/redundantcast \
|
||||
compilerplugins/clang/test/redundantcopy \
|
||||
compilerplugins/clang/test/redundantfcast \
|
||||
compilerplugins/clang/test/redundantinline \
|
||||
compilerplugins/clang/test/redundantpointerops \
|
||||
compilerplugins/clang/test/refcounting \
|
||||
|
Reference in New Issue
Block a user