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() != nullptr + && loplugin::TypeCheck(t1).ClassOrStruct("initializer_list").StdNamespace() + && isa(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 +#include #include void method1(OUString const&); // expected-note {{in call to method here [loplugin:redundantfcast]}} @@ -105,4 +106,99 @@ void f2() } } +namespace test7 +{ +// expected-note@+1 6 {{in call to method here [loplugin:redundantfcast]}} +void f1(std::initializer_list const&); +// expected-note@+1 6 {{in call to method here [loplugin:redundantfcast]}} +template void f2(std::initializer_list const&); +// expected-note@+1 4 {{in call to method here [loplugin:redundantfcast]}} +template void f3(T const&); +// expected-note@+1 4 {{in call to method here [loplugin:redundantfcast]}} +template void f4(T const&...); +void f5(int, ...); +void g(std::initializer_list il) +{ + f1(il); + f2(il); + f3(il); + f4(il); + f5(0, il); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f1(std::initializer_list(il)); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f2(std::initializer_list(il)); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f3(std::initializer_list(il)); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f4(std::initializer_list(il)); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f5(0, std::initializer_list(il)); + f1({}); + f1(std::initializer_list{}); // should warn, but not modelled as CXXFunctionalCastExpr + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f1(std::initializer_list({})); + // f2({}); //error + f2(std::initializer_list{}); // should warn, but not modelled as CXXFunctionalCastExpr + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f2(std::initializer_list({})); + // f3({}); //error + f3(std::initializer_list{}); // (not modelled as CXXFunctionalCastExpr anyway) + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f3(std::initializer_list({})); // arguably rather subtle, remove "("...")" + // f4({}); //error + f4(std::initializer_list{}); // (not modelled as CXXFunctionalCastExpr anyway) + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f4(std::initializer_list({})); // arguably rather subtle, remove "("...")" + // f5(0, {}); //error + f5(0, std::initializer_list{}); // (not modelled as CXXFunctionalCastExpr anyway) + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f5(0, std::initializer_list({})); // arguably rather subtle, remove "("...")" + f1({ 1 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f1(std::initializer_list{ 1 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f1(std::initializer_list({ 1 })); + f2({ 1 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f2(std::initializer_list{ 1 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f2(std::initializer_list({ 1 })); + // f3({1}); //error + f3(std::initializer_list{ 1 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f3(std::initializer_list({ 1 })); // arguably rather subtle, remove "("...")" + // f4({1}); //error + f4(std::initializer_list{ 1 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f4(std::initializer_list({ 1 })); // arguably rather subtle, remove "("...")" + // f5(0, {1}); //error + f5(0, std::initializer_list{ 1 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f5(0, std::initializer_list({ 1 })); // arguably rather subtle, remove "("...")" + f1({ 1, 2, 3 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f1(std::initializer_list{ 1, 2, 3 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f1(std::initializer_list({ 1, 2, 3 })); + f2({ 1, 2, 3 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f2(std::initializer_list{ 1, 2, 3 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f2(std::initializer_list({ 1, 2, 3 })); + // f3({1, 2, 3}); //error + f3(std::initializer_list{ 1, 2, 3 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f3(std::initializer_list({ 1, 2, 3 })); // arguably rather subtle, remove "("...")" + // f4({1, 2, 3}); //error + f4(std::initializer_list{ 1, 2, 3 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f4(std::initializer_list({ 1, 2, 3 })); // arguably rather subtle, remove "("...")" + // f5(0, {1, 2, 3}); //error + f5(0, std::initializer_list{ 1, 2, 3 }); + // expected-error@+1 {{redundant functional cast from 'std::initializer_list' to 'std::initializer_list' [loplugin:redundantfcast]}} + f5(0, std::initializer_list({ 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 + +#include #include #include #include @@ -63,7 +66,6 @@ #include #include #include -#include #include #include #include @@ -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{ "com.sun.star.drawing.Shape" }); } SvxShape* SwXShape::GetSvxShape()