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

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Wed Nov 20 19:54:20 UTC 2019


 compilerplugins/clang/redundantfcast.cxx      |    7 +
 compilerplugins/clang/test/redundantfcast.cxx |   96 ++++++++++++++++++++++++++
 sw/source/core/unocore/unodraw.cxx            |    6 +
 3 files changed, 107 insertions(+), 2 deletions(-)

New commits:
commit df24a0dc144c8f963f8567c17b2d1a1090558cdb
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Wed Nov 20 11:43:12 2019 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Nov 20 20:53:01 2019 +0100

    loplugin:redundantfcast: Don't warn about cast from braced-init-list
    
    ...in non-deduced context.  That means that the necessary cast in
    84322944980f6e2f9d4a531de7a6803797156968 "Simplify sequence initialization"
    (cf. <https://gerrit.libreoffice.org/#/c/82974/4/>) no longer causes a false
    positive, and doesn't need to use comphelper::OUStringLiteralList.
    
    Change-Id: I788da61cc0be82d2166653760e527bb18e366c99
    Reviewed-on: https://gerrit.libreoffice.org/83291
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/redundantfcast.cxx b/compilerplugins/clang/redundantfcast.cxx
index 260fe1852417..5084d5a29ab3 100644
--- a/compilerplugins/clang/redundantfcast.cxx
+++ b/compilerplugins/clang/redundantfcast.cxx
@@ -105,6 +105,13 @@ public:
             // something useful
             if (t1.getCanonicalType().getTypePtr() != paramClassOrStructType)
                 continue;
+            // Don't warn about (necessary) cast from braced-init-list in non-deduced contexts:
+            if (lvalueType->getPointeeType()->getAs<SubstTemplateTypeParmType>() != nullptr
+                && loplugin::TypeCheck(t1).ClassOrStruct("initializer_list").StdNamespace()
+                && isa<CXXStdInitializerListExpr>(compat::getSubExprAsWritten(functionalCast)))
+            {
+                continue;
+            }
 
             if (m_Seen.insert(arg->getExprLoc()).second)
             {
diff --git a/compilerplugins/clang/test/redundantfcast.cxx b/compilerplugins/clang/test/redundantfcast.cxx
index 985aa8c02994..255c1d44b2a7 100644
--- a/compilerplugins/clang/test/redundantfcast.cxx
+++ b/compilerplugins/clang/test/redundantfcast.cxx
@@ -13,6 +13,7 @@
 #include "tools/color.hxx"
 
 #include <functional>
+#include <initializer_list>
 #include <memory>
 
 void method1(OUString const&); // expected-note {{in call to method here [loplugin:redundantfcast]}}
@@ -105,4 +106,99 @@ void f2()
 }
 }
 
+namespace test7
+{
+// expected-note at +1 6 {{in call to method here [loplugin:redundantfcast]}}
+void f1(std::initializer_list<int> const&);
+// expected-note at +1 6 {{in call to method here [loplugin:redundantfcast]}}
+template <typename T> void f2(std::initializer_list<T> const&);
+// expected-note at +1 4 {{in call to method here [loplugin:redundantfcast]}}
+template <typename T> void f3(T const&);
+// expected-note at +1 4 {{in call to method here [loplugin:redundantfcast]}}
+template <typename... T> void f4(T const&...);
+void f5(int, ...);
+void g(std::initializer_list<int> il)
+{
+    f1(il);
+    f2(il);
+    f3(il);
+    f4(il);
+    f5(0, il);
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f1(std::initializer_list<int>(il));
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f2(std::initializer_list<int>(il));
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f3(std::initializer_list<int>(il));
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f4(std::initializer_list<int>(il));
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f5(0, std::initializer_list<int>(il));
+    f1({});
+    f1(std::initializer_list<int>{}); // should warn, but not modelled as CXXFunctionalCastExpr
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f1(std::initializer_list<int>({}));
+    // f2({}); //error
+    f2(std::initializer_list<int>{}); // should warn, but not modelled as CXXFunctionalCastExpr
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f2(std::initializer_list<int>({}));
+    // f3({}); //error
+    f3(std::initializer_list<int>{}); // (not modelled as CXXFunctionalCastExpr anyway)
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f3(std::initializer_list<int>({})); // arguably rather subtle, remove "("...")"
+    // f4({}); //error
+    f4(std::initializer_list<int>{}); // (not modelled as CXXFunctionalCastExpr anyway)
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f4(std::initializer_list<int>({})); // arguably rather subtle, remove "("...")"
+    // f5(0, {}); //error
+    f5(0, std::initializer_list<int>{}); // (not modelled as CXXFunctionalCastExpr anyway)
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f5(0, std::initializer_list<int>({})); // arguably rather subtle, remove "("...")"
+    f1({ 1 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f1(std::initializer_list<int>{ 1 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f1(std::initializer_list<int>({ 1 }));
+    f2({ 1 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f2(std::initializer_list<int>{ 1 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f2(std::initializer_list<int>({ 1 }));
+    // f3({1}); //error
+    f3(std::initializer_list<int>{ 1 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f3(std::initializer_list<int>({ 1 })); // arguably rather subtle, remove "("...")"
+    // f4({1}); //error
+    f4(std::initializer_list<int>{ 1 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f4(std::initializer_list<int>({ 1 })); // arguably rather subtle, remove "("...")"
+    // f5(0, {1}); //error
+    f5(0, std::initializer_list<int>{ 1 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f5(0, std::initializer_list<int>({ 1 })); // arguably rather subtle, remove "("...")"
+    f1({ 1, 2, 3 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f1(std::initializer_list<int>{ 1, 2, 3 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f1(std::initializer_list<int>({ 1, 2, 3 }));
+    f2({ 1, 2, 3 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f2(std::initializer_list<int>{ 1, 2, 3 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f2(std::initializer_list<int>({ 1, 2, 3 }));
+    // f3({1, 2, 3}); //error
+    f3(std::initializer_list<int>{ 1, 2, 3 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f3(std::initializer_list<int>({ 1, 2, 3 })); // arguably rather subtle, remove "("...")"
+    // f4({1, 2, 3}); //error
+    f4(std::initializer_list<int>{ 1, 2, 3 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f4(std::initializer_list<int>({ 1, 2, 3 })); // arguably rather subtle, remove "("...")"
+    // f5(0, {1, 2, 3}); //error
+    f5(0, std::initializer_list<int>{ 1, 2, 3 });
+    // expected-error at +1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
+    f5(0, std::initializer_list<int>({ 1, 2, 3 })); // arguably rather subtle, remove "("...")"
+}
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index c73614a61bc7..4d14d25467e1 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -17,6 +17,9 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/config.h>
+
+#include <initializer_list>
 #include <memory>
 #include <sal/config.h>
 #include <sal/log.hxx>
@@ -63,7 +66,6 @@
 #include <crstate.hxx>
 #include <comphelper/extract.hxx>
 #include <comphelper/profilezone.hxx>
-#include <comphelper/OUStringLiteralList.hxx>
 #include <comphelper/sequence.hxx>
 #include <cppuhelper/supportsservice.hxx>
 #include <svx/scene3d.hxx>
@@ -2149,7 +2151,7 @@ uno::Sequence< OUString > SwXShape::getSupportedServiceNames()
     if (SvxShape* pSvxShape = GetSvxShape())
         aSeq = pSvxShape->getSupportedServiceNames();
     return comphelper::concatSequences(
-        aSeq, comphelper::OUStringLiteralList({ "com.sun.star.drawing.Shape" }));
+        aSeq, std::initializer_list<OUStringLiteral>{ "com.sun.star.drawing.Shape" });
 }
 
 SvxShape*   SwXShape::GetSvxShape()


More information about the Libreoffice-commits mailing list