summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-02-22 08:55:08 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-02-22 08:56:29 +0200
commit50d0ec571f302fe54ac7ddac827b571c94554bec (patch)
tree92f630d1bfd8feb9cc1814e7b9a7b9db00b7a66a /compilerplugins
parent38604d6cbeb79731aec023615fa0972dda7715b1 (diff)
rename redundantcopy loplugin to redundantfcast
Change-Id: I34e28a30a4f1fd264c18c901cd94094531543271
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/redundantfcast.cxx (renamed from compilerplugins/clang/redundantcopy.cxx)39
-rw-r--r--compilerplugins/clang/test/redundantcopy.cxx40
-rw-r--r--compilerplugins/clang/test/redundantfcast.cxx48
3 files changed, 68 insertions, 59 deletions
diff --git a/compilerplugins/clang/redundantcopy.cxx b/compilerplugins/clang/redundantfcast.cxx
index bffe89014eeb..87d656c6d237 100644
--- a/compilerplugins/clang/redundantcopy.cxx
+++ b/compilerplugins/clang/redundantfcast.cxx
@@ -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: */
diff --git a/compilerplugins/clang/test/redundantcopy.cxx b/compilerplugins/clang/test/redundantcopy.cxx
deleted file mode 100644
index 0e3e7f0377c2..000000000000
--- a/compilerplugins/clang/test/redundantcopy.cxx
+++ /dev/null
@@ -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: */
diff --git a/compilerplugins/clang/test/redundantfcast.cxx b/compilerplugins/clang/test/redundantfcast.cxx
new file mode 100644
index 000000000000..f642098ed00f
--- /dev/null
+++ b/compilerplugins/clang/test/redundantfcast.cxx
@@ -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: */