summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-10-12 16:23:33 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-10-13 07:18:41 +0200
commitaf2879e434fa0dc6b2a626617ed865e4f66eb5ad (patch)
treebb25da5b207884ab9fd8d1c49d8dee18b9f1ad12 /compilerplugins
parentb3869749719288e6d1951030f07dc3fbccc0c222 (diff)
Deduplicate stringconcat more
In the process, drop ToStringHelper::allowO(U)StringConcat, because we can deduce this information from ToStringHelper's addData itself. To do that, addData was converted to ToStringHelper::operator(), which allows to use std::is_invocable_v on the helper class. Change-Id: Ic77878ca0ff65ada8c0a942191bc11de15b9ad2a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141254 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/stringadd.cxx1
-rw-r--r--compilerplugins/clang/stringconcatauto.cxx8
-rw-r--r--compilerplugins/clang/stringview.cxx7
-rw-r--r--compilerplugins/clang/test/stringconcatauto.cxx12
-rw-r--r--compilerplugins/clang/test/stringview.cxx4
5 files changed, 19 insertions, 13 deletions
diff --git a/compilerplugins/clang/stringadd.cxx b/compilerplugins/clang/stringadd.cxx
index 339192a78687..9254e9190ed5 100644
--- a/compilerplugins/clang/stringadd.cxx
+++ b/compilerplugins/clang/stringadd.cxx
@@ -233,6 +233,7 @@ bool StringAdd::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* operatorCall
auto tc = loplugin::TypeCheck(operatorCall->getType()->getUnqualifiedDesugaredType());
if (!tc.Struct("OUStringConcat").Namespace("rtl").GlobalNamespace()
&& !tc.Struct("OStringConcat").Namespace("rtl").GlobalNamespace()
+ && !tc.Struct("StringConcat").Namespace("rtl").GlobalNamespace()
&& !tc.Class("OUString").Namespace("rtl").GlobalNamespace()
&& !tc.Class("OString").Namespace("rtl").GlobalNamespace())
return true;
diff --git a/compilerplugins/clang/stringconcatauto.cxx b/compilerplugins/clang/stringconcatauto.cxx
index 561aedec8070..02517a4db0ba 100644
--- a/compilerplugins/clang/stringconcatauto.cxx
+++ b/compilerplugins/clang/stringconcatauto.cxx
@@ -83,10 +83,10 @@ bool StringConcatAuto::checkDecl( const DeclaratorDecl* decl, QualType type, con
return true;
auto const tc = loplugin::TypeCheck( type.getNonReferenceType().getCanonicalType());
const char* typeString = nullptr;
- if( tc.Struct("OUStringConcat").Namespace("rtl").GlobalNamespace())
- typeString = "OUString";
- else if( tc.Struct("OStringConcat").Namespace("rtl").GlobalNamespace())
- typeString = "OString";
+ if( tc.Struct("StringConcat").Namespace("rtl").GlobalNamespace())
+ typeString = "O(U)String";
+ else if( tc.Struct("StringNumber").Namespace("rtl").GlobalNamespace())
+ typeString = "O(U)String";
else if( tc.Struct("OUStringNumber").Namespace("rtl").GlobalNamespace())
typeString = "OUString";
else if( tc.Struct("OStringNumber").Namespace("rtl").GlobalNamespace())
diff --git a/compilerplugins/clang/stringview.cxx b/compilerplugins/clang/stringview.cxx
index c1606908dbc7..16e53b1c12e9 100644
--- a/compilerplugins/clang/stringview.cxx
+++ b/compilerplugins/clang/stringview.cxx
@@ -206,6 +206,10 @@ void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr)
.Class("OUStringLiteral")
.Namespace("rtl")
.GlobalNamespace()
+ || tc.RvalueReference()
+ .Struct("StringNumberBase")
+ .Namespace("rtl")
+ .GlobalNamespace()
|| tc.RvalueReference().Struct("OStringNumber").Namespace("rtl").GlobalNamespace()
|| tc.RvalueReference().Struct("OUStringNumber").Namespace("rtl").GlobalNamespace()
|| tc.ClassOrStruct("basic_string_view").StdNamespace())
@@ -214,7 +218,8 @@ void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr)
break;
}
if (tc.RvalueReference().Struct("OStringConcat").Namespace("rtl").GlobalNamespace()
- || tc.RvalueReference().Struct("OUStringConcat").Namespace("rtl").GlobalNamespace())
+ || tc.RvalueReference().Struct("OUStringConcat").Namespace("rtl").GlobalNamespace()
+ || tc.RvalueReference().Struct("StringConcat").Namespace("rtl").GlobalNamespace())
{
argType = expr->getArg(0)->IgnoreImplicit()->getType();
extra = ViaConcatenation;
diff --git a/compilerplugins/clang/test/stringconcatauto.cxx b/compilerplugins/clang/test/stringconcatauto.cxx
index dc450503d25e..72044f80b150 100644
--- a/compilerplugins/clang/test/stringconcatauto.cxx
+++ b/compilerplugins/clang/test/stringconcatauto.cxx
@@ -15,14 +15,14 @@ void foo()
{
auto str1 = "str1" + OUString::number(10);
// expected-error-re@-1 {{creating a variable of type {{.+}} will make it reference temporaries}}
- // expected-note@-2 {{use OUString instead}}
+ // expected-note@-2 {{use O(U)String instead}}
OUString str2 = "str2" + OUString::number(20) + "ing";
const auto& str3 = "str3" + OUString::number(30);
// expected-error-re@-1 {{creating a variable of type {{.+}} will make it reference temporaries}}
- // expected-note@-2 {{use OUString instead}}
+ // expected-note@-2 {{use O(U)String instead}}
const auto str4 = "str4" + OString::number(40);
// expected-error-re@-1 {{creating a variable of type {{.+}} will make it reference temporaries}}
- // expected-note@-2 {{use OString instead}}
+ // expected-note@-2 {{use O(U)String instead}}
auto str5 = OUString::number(50);
// expected-error-re@-1 {{creating a variable of type '{{(rtl::)?}}OUStringNumber<{{.*}}>' will make it reference temporaries}}
// expected-note@-2 {{use OUString instead}}
@@ -37,7 +37,7 @@ struct A
{
auto bar()
// expected-error-re@-1 {{returning a variable of type {{.+}} will make it reference temporaries}}
- // expected-note@-2 {{use OString instead}}
+ // expected-note@-2 {{use O(U)String instead}}
{
return "bar" + OString::number(110);
}
@@ -53,8 +53,8 @@ template <typename T> void fun(const T& par)
// parameters are without warnings
{
const T& var = par;
- // expected-error-re@-1 {{creating a variable of type 'const rtl::OUStringConcat<{{.*}}> &' will make it reference temporaries}}
- // expected-note@-2 {{use OUString instead}}
+ // expected-error-re@-1 {{creating a variable of type 'const rtl::StringConcat<{{.*}}> &' will make it reference temporaries}}
+ // expected-note@-2 {{use O(U)String instead}}
(void)var;
}
diff --git a/compilerplugins/clang/test/stringview.cxx b/compilerplugins/clang/test/stringview.cxx
index f578a5f50e8d..cd59f6c3c73a 100644
--- a/compilerplugins/clang/test/stringview.cxx
+++ b/compilerplugins/clang/test/stringview.cxx
@@ -167,7 +167,7 @@ void f5(char const* s1, sal_Int32 n1, char16_t const* s2, sal_Int32 n2, OString
call_view(OString(std::string_view("foo")));
// expected-error-re@+1 {{instead of an '{{(rtl::)?}}OString' constructed from a 'OStringNumber<int>', pass a 'std::string_view' [loplugin:stringview]}}
call_view(OString(OString::number(0)));
- // expected-error-re@+1 {{instead of an '{{(rtl::)?}}OString' constructed from a 'typename std::enable_if_t<ToStringHelper<OString>::allowOStringConcat && ToStringHelper<OString>::allowOStringConcat, OStringConcat<OString, OString>{{ ?}}>' (aka 'rtl::OStringConcat<rtl::OString, rtl::OString>'), pass a 'std::string_view' via 'rtl::Concat2View' [loplugin:stringview]}}
+ // expected-error-re@+1 {{instead of an '{{(rtl::)?}}OString' constructed from a 'OStringConcat<rtl::OString, rtl::OString>' (aka 'StringConcat<char, rtl::OString, rtl::OString>'), pass a 'std::string_view' via 'rtl::Concat2View' [loplugin:stringview]}}
call_view(OString(s3 + s3));
// expected-error-re@+1 {{instead of an '{{(rtl::)?}}OUString', pass a 'std::u16string_view' [loplugin:stringview]}}
call_view(OUString());
@@ -192,7 +192,7 @@ void f5(char const* s1, sal_Int32 n1, char16_t const* s2, sal_Int32 n2, OString
call_view(OUString(std::u16string_view(u"foo")));
// expected-error-re@+1 {{instead of an '{{(rtl::)?}}OUString' constructed from a 'OUStringNumber<int>', pass a 'std::u16string_view' [loplugin:stringview]}}
call_view(OUString(OUString::number(0)));
- // expected-error-re@+1 {{instead of an '{{(rtl::)?}}OUString' constructed from a 'typename std::enable_if_t<ToStringHelper<OUString>::allowOUStringConcat && ToStringHelper<OUString>::allowOUStringConcat, OUStringConcat<OUString, OUString>{{ ?}}>' (aka 'rtl::OUStringConcat<rtl::OUString, rtl::OUString>'), pass a 'std::u16string_view' via 'rtl::Concat2View' [loplugin:stringview]}}
+ // expected-error-re@+1 {{instead of an '{{(rtl::)?}}OUString' constructed from a 'OUStringConcat<rtl::OUString, rtl::OUString>' (aka 'StringConcat<char16_t, rtl::OUString, rtl::OUString>'), pass a 'std::u16string_view' via 'rtl::Concat2View' [loplugin:stringview]}}
call_view(OUString(s4 + s4));
(void)(s3 == l1);