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

Make loplugin:stringconcat more robust

Change-Id: Ib8adefd90141007c0422b4c15ba9c2cc5f707f3f
Reviewed-on: https://gerrit.libreoffice.org/67762
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst e6984376
......@@ -13,32 +13,36 @@
namespace {
Expr const * stripCtor(Expr const * expr) {
auto e0 = expr;
auto const e1 = dyn_cast<CXXFunctionalCastExpr>(e0);
if (e1 != nullptr) {
e0 = e1->getSubExpr()->IgnoreParenImpCasts();
auto e1 = expr;
if (auto const e = dyn_cast<CXXFunctionalCastExpr>(e1)) {
e1 = e->getSubExpr()->IgnoreParenImpCasts();
}
auto const e2 = dyn_cast<CXXBindTemporaryExpr>(e0);
if (auto const e = dyn_cast<CXXBindTemporaryExpr>(e1)) {
e1 = e->getSubExpr()->IgnoreParenImpCasts();
}
auto const e2 = dyn_cast<CXXConstructExpr>(e1);
if (e2 == nullptr) {
return expr;
}
auto const e3 = dyn_cast<CXXConstructExpr>(
e2->getSubExpr()->IgnoreParenImpCasts());
if (e3 == nullptr) {
auto qt = loplugin::DeclCheck(e2->getConstructor());
if (qt.MemberFunction().Struct("OStringLiteral").Namespace("rtl").GlobalNamespace()) {
if (e2->getNumArgs() == 1) {
return e2->getArg(0)->IgnoreParenImpCasts();
}
return expr;
}
auto qt = loplugin::DeclCheck(e3->getConstructor());
if (!((qt.MemberFunction().Class("OString").Namespace("rtl")
.GlobalNamespace())
|| (qt.MemberFunction().Class("OUString").Namespace("rtl")
.GlobalNamespace())))
.GlobalNamespace())
|| qt.MemberFunction().Struct("OUStringLiteral").Namespace("rtl").GlobalNamespace()))
{
return expr;
}
if (e3->getNumArgs() != 2) {
if (e2->getNumArgs() != 2) {
return expr;
}
return e3->getArg(0)->IgnoreParenImpCasts();
return e2->getArg(0)->IgnoreParenImpCasts();
}
class StringConcat:
......@@ -100,6 +104,8 @@ bool StringConcat::VisitCallExpr(CallExpr const * expr) {
getFileNameOfSpellingLoc(
compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr))) };
if (loplugin::isSamePathname(
name, SRCDIR "/sal/qa/rtl/oustringbuffer/test_oustringbuffer_assign.cxx")
|| loplugin::isSamePathname(
name, SRCDIR "/sal/qa/rtl/strings/test_ostring_concat.cxx")
|| loplugin::isSamePathname(
name, SRCDIR "/sal/qa/rtl/strings/test_oustring_concat.cxx"))
......
/* -*- 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 <ostream>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
#define FOO "foo"
void f(std::ostream& s1)
{
static char const foo[] = "foo";
s1 << "foo"
<< "foo";
// expected-error@-1 {{replace '<<' between string literals with juxtaposition}}
s1 << "foo" << FOO;
// expected-error@-1 {{replace '<<' between string literals with juxtaposition}}
s1 << "foo" << foo;
s1 << "foo" << OString("foo");
// expected-error@-1 {{replace '<<' between string literals with juxtaposition}}
s1 << "foo" << OString(FOO);
// expected-error@-1 {{replace '<<' between string literals with juxtaposition}}
s1 << "foo" << OString(foo);
s1 << "foo" << OUString("foo");
// expected-error@-1 {{replace '<<' between string literals with juxtaposition}}
s1 << "foo" << OUString(FOO);
// expected-error@-1 {{replace '<<' between string literals with juxtaposition}}
s1 << "foo" << OUString(foo);
s1 << "foo" << OUStringLiteral("foo"); //TODO: warn too, OUStringLiteral wrapped in OUString
s1 << "foo" << OUStringLiteral(FOO); //TODO: warn too, OUStringLiteral wrapped in OUString
s1 << "foo" << OUStringLiteral(foo);
OString s2;
s2 = "foo" + OString("foo");
// expected-error@-1 {{replace '+' between string literals with juxtaposition}}
s2 = "foo" + OString(FOO);
// expected-error@-1 {{replace '+' between string literals with juxtaposition}}
s2 = "foo" + OString(foo);
s2 = "foo" + OStringLiteral("foo");
// expected-error@-1 {{replace '+' between string literals with juxtaposition}}
s2 = "foo" + OStringLiteral(FOO);
// expected-error@-1 {{replace '+' between string literals with juxtaposition}}
s2 = "foo" + OStringLiteral(foo);
OUString s3;
s3 = "foo" + OUString("foo");
// expected-error@-1 {{replace '+' between string literals with juxtaposition}}
s3 = "foo" + OUString(FOO);
// expected-error@-1 {{replace '+' between string literals with juxtaposition}}
s3 = "foo" + OUString(foo);
s3 = "foo" + OUStringLiteral("foo");
// expected-error@-1 {{replace '+' between string literals with juxtaposition}}
s3 = "foo" + OUStringLiteral(FOO);
// expected-error@-1 {{replace '+' between string literals with juxtaposition}}
s3 = "foo" + OUStringLiteral(foo);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -58,6 +58,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/staticconstfield \
compilerplugins/clang/test/staticvar \
compilerplugins/clang/test/stringbuffer \
compilerplugins/clang/test/stringconcat \
compilerplugins/clang/test/stringconstant \
compilerplugins/clang/test/stringloop \
compilerplugins/clang/test/unnecessarycatchthrow \
......
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