[Libreoffice-commits] core.git: compilerplugins/clang solenv/CompilerTest_compilerplugins_clang.mk
Stephan Bergmann
sbergman at redhat.com
Tue Jun 13 15:02:25 UTC 2017
compilerplugins/clang/redundantcopy.cxx | 14 +++++++++-----
compilerplugins/clang/test/redundantcopy.cxx | 10 +++++++---
solenv/CompilerTest_compilerplugins_clang.mk | 2 +-
3 files changed, 17 insertions(+), 9 deletions(-)
New commits:
commit 423dacde87cbb3cba466c9701ed10dadc2b8b4e0
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Tue Jun 13 17:00:30 2017 +0200
Generalize loplugin:stringcopy to loplugin:redundantcopy
(such redundant std::unique_ptr copies could happen when changing parts of the
code base to make use of std::unique_ptr individually)
Change-Id: Ib48a45a212f9426a775c7f379bc5d3c92230218a
diff --git a/compilerplugins/clang/stringcopy.cxx b/compilerplugins/clang/redundantcopy.cxx
similarity index 78%
rename from compilerplugins/clang/stringcopy.cxx
rename to compilerplugins/clang/redundantcopy.cxx
index b1d8e22216ec..18190f1eb0e4 100644
--- a/compilerplugins/clang/stringcopy.cxx
+++ b/compilerplugins/clang/redundantcopy.cxx
@@ -25,10 +25,14 @@ public:
}
auto const t1 = expr->getTypeAsWritten();
auto const t2 = compat::getSubExprAsWritten(expr)->getType();
- if ((t1.getCanonicalType().getTypePtr()
- != t2.getCanonicalType().getTypePtr())
- || !(loplugin::TypeCheck(t1).Class("OUString").Namespace("rtl")
- .GlobalNamespace()))
+ if (t1.getCanonicalType().getTypePtr()
+ != t2.getCanonicalType().getTypePtr())
+ {
+ return true;
+ }
+ auto tc = loplugin::TypeCheck(t1);
+ if (!(tc.Class("OUString").Namespace("rtl").GlobalNamespace()
+ || tc.Class("unique_ptr").StdNamespace()))
{
return true;
}
@@ -47,7 +51,7 @@ private:
}
};
-static loplugin::Plugin::Registration<Visitor> reg("stringcopy");
+static loplugin::Plugin::Registration<Visitor> reg("redundantcopy");
}
diff --git a/compilerplugins/clang/test/stringcopy.cxx b/compilerplugins/clang/test/redundantcopy.cxx
similarity index 68%
rename from compilerplugins/clang/test/stringcopy.cxx
rename to compilerplugins/clang/test/redundantcopy.cxx
index c801b7096f74..24207a60be69 100644
--- a/compilerplugins/clang/test/stringcopy.cxx
+++ b/compilerplugins/clang/test/redundantcopy.cxx
@@ -9,15 +9,19 @@
#include "sal/config.h"
+#include <memory>
+
#include "rtl/ustring.hxx"
int main() {
OUString s;
- (void) OUString(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'rtl::OUString' [loplugin:stringcopy]}}
+ (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:stringcopy]}}
+ (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:stringcopy]}}
+ (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]}}
}
/* 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 d85ba6d9f58e..4e65a684efd4 100644
--- a/solenv/CompilerTest_compilerplugins_clang.mk
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -20,11 +20,11 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/oslendian-2 \
compilerplugins/clang/test/oslendian-3 \
compilerplugins/clang/test/redundantcast \
+ compilerplugins/clang/test/redundantcopy \
compilerplugins/clang/test/redundantinline \
compilerplugins/clang/test/salbool \
compilerplugins/clang/test/salunicodeliteral \
compilerplugins/clang/test/stringconstant \
- compilerplugins/clang/test/stringcopy \
compilerplugins/clang/test/unnecessaryoverride-dtor \
compilerplugins/clang/test/unoany \
compilerplugins/clang/test/useuniqueptr \
More information about the Libreoffice-commits
mailing list