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

loplugin:stringcopy

Change-Id: Ib04ef019996888166c25ad140b7c718a173a782a
üst 0e4a884b
/* -*- 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 "check.hxx"
#include "plugin.hxx"
namespace {
class Visitor final:
public RecursiveASTVisitor<Visitor>, public loplugin::Plugin
{
public:
explicit Visitor(InstantiationData const & data): Plugin(data) {}
bool VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * expr) {
if (ignoreLocation(expr)) {
return true;
}
auto const t1 = expr->getTypeAsWritten();
auto const t2 = expr->getSubExprAsWritten()->getType();
if ((t1.getCanonicalType().getTypePtr()
!= t2.getCanonicalType().getTypePtr())
|| !(loplugin::TypeCheck(t1).Class("OUString").Namespace("rtl")
.GlobalNamespace()))
{
return true;
}
report(
DiagnosticsEngine::Warning,
"redundant copy construction from %0 to %1", expr->getExprLoc())
<< t2 << t1 << expr->getSourceRange();
return true;
}
private:
void run() override {
if (compiler.getLangOpts().CPlusPlus) {
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
}
};
static loplugin::Plugin::Registration<Visitor> reg("stringcopy");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
/* -*- 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 "rtl/ustring.hxx"
int main() {
OUString s;
(void) OUString(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'rtl::OUString' [loplugin:stringcopy]}}
using T1 = OUString;
(void) T1(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'T1' (aka 'rtl::OUString') [loplugin:stringcopy]}}
using T2 = OUString const;
(void) T2(s); // expected-error {{redundant copy construction from 'rtl::OUString' to 'T2' (aka 'const rtl::OUString') [loplugin:stringcopy]}}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -24,6 +24,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
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/vclwidgets \
......
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