[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Wed Dec 9 22:25:40 UTC 2020


 compilerplugins/clang/stringview.cxx      |    7 +++++--
 compilerplugins/clang/test/stringview.cxx |    6 ++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

New commits:
commit ff8d82dc4cc0841f11ad6d51d3ed37450a6f6971
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Wed Dec 9 22:44:49 2020 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Dec 9 23:25:00 2020 +0100

    Improve loplugin:stringview diagnostic messages
    
    Change-Id: If1b94de205fb9c1cc0491603f27073dfde67a485
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107511
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/stringview.cxx b/compilerplugins/clang/stringview.cxx
index 26af817659be..abfc87f78fd6 100644
--- a/compilerplugins/clang/stringview.cxx
+++ b/compilerplugins/clang/stringview.cxx
@@ -143,6 +143,7 @@ bool StringView::VisitImplicitCastExpr(ImplicitCastExpr const* expr)
 
 void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr)
 {
+    bool charArg = false;
     auto const d = expr->getConstructor();
     switch (d->getNumParams())
     {
@@ -153,6 +154,7 @@ void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr)
             auto const t = d->getParamDecl(0)->getType();
             if (t->isAnyCharacterType())
             {
+                charArg = true;
                 break;
             }
             loplugin::TypeCheck tc(t);
@@ -200,13 +202,14 @@ void StringView::handleCXXConstructExpr(CXXConstructExpr const* expr)
             return;
     }
     report(DiagnosticsEngine::Warning,
-           "instead of an %0, pass a '%select{std::string_view|std::u16string_view}1'",
+           "instead of an %0, pass a '%select{std::string_view|std::u16string_view}1'"
+           "%select{| (or an '%select{rtl::OStringChar|rtl::OUStringChar}1')}2",
            expr->getExprLoc())
         << expr->getType()
         << (loplugin::TypeCheck(expr->getType()).Class("OString").Namespace("rtl").GlobalNamespace()
                 ? 0
                 : 1)
-        << expr->getSourceRange();
+        << charArg << expr->getSourceRange();
 }
 
 void StringView::handleCXXMemberCallExpr(CXXMemberCallExpr const* expr)
diff --git a/compilerplugins/clang/test/stringview.cxx b/compilerplugins/clang/test/stringview.cxx
index 651e49e7bc27..d40ee50175a1 100644
--- a/compilerplugins/clang/test/stringview.cxx
+++ b/compilerplugins/clang/test/stringview.cxx
@@ -104,7 +104,7 @@ void f5(char const* s1, sal_Int32 n1, char16_t const* s2, sal_Int32 n2)
     call_view(OString());
     // expected-error at +1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}}
     call_view(OString("foo"));
-    // expected-error at +1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}}
+    // expected-error at +1 {{instead of an 'rtl::OString', pass a 'std::string_view' (or an 'rtl::OStringChar') [loplugin:stringview]}}
     call_view(OString(*s1));
     // expected-error at +1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}}
     call_view(OString(s1));
@@ -123,7 +123,9 @@ void f5(char const* s1, sal_Int32 n1, char16_t const* s2, sal_Int32 n2)
     call_view(OUString("foo"));
     // expected-error at +1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}}
     call_view(OUString(u"foo"));
-    // expected-error at +1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}}
+    // expected-error at +1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' (or an 'rtl::OUStringChar') [loplugin:stringview]}}
+    call_view(OUString(*s1));
+    // expected-error at +1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' (or an 'rtl::OUStringChar') [loplugin:stringview]}}
     call_view(OUString(*s2));
     // expected-error at +1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}}
     call_view(OUString(s2));


More information about the Libreoffice-commits mailing list