[Libreoffice-commits] core.git: compilerplugins/clang solenv/CompilerTest_compilerplugins_clang.mk

Noel Grandin noel.grandin at collabora.co.uk
Thu Feb 22 06:57:07 UTC 2018


 compilerplugins/clang/redundantfcast.cxx      |   39 ++++++++++-----------
 compilerplugins/clang/test/redundantcopy.cxx  |   40 ---------------------
 compilerplugins/clang/test/redundantfcast.cxx |   48 ++++++++++++++++++++++++++
 solenv/CompilerTest_compilerplugins_clang.mk  |    2 -
 4 files changed, 69 insertions(+), 60 deletions(-)

New commits:
commit 50d0ec571f302fe54ac7ddac827b571c94554bec
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Feb 22 08:55:08 2018 +0200

    rename redundantcopy loplugin to redundantfcast
    
    Change-Id: I34e28a30a4f1fd264c18c901cd94094531543271

diff --git a/compilerplugins/clang/redundantcopy.cxx b/compilerplugins/clang/redundantfcast.cxx
similarity index 57%
rename from compilerplugins/clang/redundantcopy.cxx
rename to 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 at -1 {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantfcast]}}
+    using T1 = OUString;
+    (void)T1(
+        s); // expected-error at -1 {{redundant functional cast from 'rtl::OUString' to 'T1' (aka 'rtl::OUString') [loplugin:redundantfcast]}}
+    using T2 = OUString const;
+    (void)T2(
+        s); // expected-error at -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 at -1 {{redundant functional cast from 'std::unique_ptr<int>' to 'std::unique_ptr<int>' [loplugin:redundantfcast]}}
+
+    OUString s1;
+    method1(OUString(
+        s1)); // expected-error at -1 {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantfcast]}}
+
+    OUString s2;
+    s2 = OUString(
+        s1); // expected-error at -1 {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantfcast]}}
+
+    Color col1;
+    Color col2 = Color(
+        col1); // expected-error at -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: */
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk
index 018740f932a3..bc4fbdc3ae0c 100644
--- a/solenv/CompilerTest_compilerplugins_clang.mk
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -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 \


More information about the Libreoffice-commits mailing list