diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-06-13 17:00:30 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-06-13 17:00:30 +0200 |
commit | 423dacde87cbb3cba466c9701ed10dadc2b8b4e0 (patch) | |
tree | 416c47876816032c6ea072716e0154deaa534d29 /compilerplugins | |
parent | f9cf614e7ea73e47a71cd2c0d1d53af9a6e48984 (diff) |
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
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/redundantcopy.cxx (renamed from compilerplugins/clang/stringcopy.cxx) | 14 | ||||
-rw-r--r-- | compilerplugins/clang/test/redundantcopy.cxx (renamed from compilerplugins/clang/test/stringcopy.cxx) | 10 |
2 files changed, 16 insertions, 8 deletions
diff --git a/compilerplugins/clang/stringcopy.cxx b/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 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: */ |