compilerplugins/clang/stringadd.cxx      |   14 ++++++++++----
 compilerplugins/clang/test/stringadd.cxx |   15 +++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

New commits:
commit 856fc80439c23d4473930b92e201ebd33b20fc8b
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Mon Apr 17 09:09:14 2023 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Mon Apr 17 10:48:52 2023 +0200

    loplugin:stringadd: Adapt O[U]StringBuffer ctor detection for Windows
    
    ...where sal_Int32 is not int, so a literal argument like 16 actually calls 
the
    
      O[U]StringBuffer(T length, std::enable_if_t<std::is_integral_v<T>, int> = 
0)
    
    overload
    
    Change-Id: I1d151efbc723cbfa76690e02491b05a9a4147e91
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150473
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/compilerplugins/clang/stringadd.cxx 
b/compilerplugins/clang/stringadd.cxx
index bf00ef2dc1d9..022bffa804fc 100644
--- a/compilerplugins/clang/stringadd.cxx
+++ b/compilerplugins/clang/stringadd.cxx
@@ -160,10 +160,16 @@ StringAdd::VarDeclAndSummands 
StringAdd::findAssignOrAdd(Stmt const* stmt)
                     // ignore the constructor that gives the buffer a default 
size
                     if (auto cxxConstructor = 
dyn_cast<CXXConstructExpr>(varDeclLHS->getInit()))
                         if (auto constructorDecl = 
cxxConstructor->getConstructor())
-                            if (constructorDecl->getNumParams() == 1
-                                && 
loplugin::TypeCheck(constructorDecl->getParamDecl(0)->getType())
-                                       .Typedef("sal_Int32")
-                                       .GlobalNamespace())
+                            if ((constructorDecl->getNumParams() == 1
+                                 && 
loplugin::TypeCheck(constructorDecl->getParamDecl(0)->getType())
+                                        .Typedef("sal_Int32")
+                                        .GlobalNamespace())
+                                || (constructorDecl->getNumParams() == 2
+                                    && 
constructorDecl->getParamDecl(0)->getType()->isIntegralType(
+                                           compiler.getASTContext())
+                                    && constructorDecl->getParamDecl(1)
+                                           ->getType()
+                                           
->isSpecificBuiltinType(BuiltinType::Int)))
                                 return {};
                 }
                 return { varDeclLHS, 
(isCompileTimeConstant(varDeclLHS->getInit())
diff --git a/compilerplugins/clang/test/stringadd.cxx 
b/compilerplugins/clang/test/stringadd.cxx
index 3ac2bb60ebe8..7c1193643303 100644
--- a/compilerplugins/clang/test/stringadd.cxx
+++ b/compilerplugins/clang/test/stringadd.cxx
@@ -297,4 +297,19 @@ void f1()
 }
 }
 
+namespace test14
+{
+void f1()
+{
+    OUStringBuffer b(16);
+    b.append("...");
+}
+
+void f2(long long n)
+{
+    OUStringBuffer b(n);
+    b.append("...");
+}
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to