Kaydet (Commit) 423dacde authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst f9cf614e
......@@ -25,10 +25,14 @@ public:
}
auto const t1 = expr->getTypeAsWritten();
auto const t2 = compat::getSubExprAsWritten(expr)->getType();
if ((t1.getCanonicalType().getTypePtr()
if (t1.getCanonicalType().getTypePtr()
!= t2.getCanonicalType().getTypePtr())
|| !(loplugin::TypeCheck(t1).Class("OUString").Namespace("rtl")
.GlobalNamespace()))
{
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");
}
......
......@@ -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: */
......@@ -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 \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment