loplugin:redundantfcast: Don't warn about cast from braced-init-list
...in non-deduced context. That means that the necessary cast in
8432294498
"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@redhat.com>
This commit is contained in:
@@ -105,6 +105,13 @@ public:
|
|||||||
// something useful
|
// something useful
|
||||||
if (t1.getCanonicalType().getTypePtr() != paramClassOrStructType)
|
if (t1.getCanonicalType().getTypePtr() != paramClassOrStructType)
|
||||||
continue;
|
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)
|
if (m_Seen.insert(arg->getExprLoc()).second)
|
||||||
{
|
{
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
#include "tools/color.hxx"
|
#include "tools/color.hxx"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <initializer_list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
void method1(OUString const&); // expected-note {{in call to method here [loplugin:redundantfcast]}}
|
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<int> const&);
|
||||||
|
// expected-note@+1 6 {{in call to method here [loplugin:redundantfcast]}}
|
||||||
|
template <typename T> void f2(std::initializer_list<T> const&);
|
||||||
|
// expected-note@+1 4 {{in call to method here [loplugin:redundantfcast]}}
|
||||||
|
template <typename T> void f3(T const&);
|
||||||
|
// expected-note@+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@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
|
||||||
|
f1(std::initializer_list<int>(il));
|
||||||
|
// expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
|
||||||
|
f2(std::initializer_list<int>(il));
|
||||||
|
// expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
|
||||||
|
f3(std::initializer_list<int>(il));
|
||||||
|
// expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
|
||||||
|
f4(std::initializer_list<int>(il));
|
||||||
|
// expected-error@+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@+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@+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@+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@+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@+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@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
|
||||||
|
f1(std::initializer_list<int>{ 1 });
|
||||||
|
// expected-error@+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@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
|
||||||
|
f2(std::initializer_list<int>{ 1 });
|
||||||
|
// expected-error@+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@+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@+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@+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@+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@+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@+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@+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@+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@+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@+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: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||||
|
@@ -17,6 +17,9 @@
|
|||||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sal/config.h>
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sal/config.h>
|
#include <sal/config.h>
|
||||||
#include <sal/log.hxx>
|
#include <sal/log.hxx>
|
||||||
@@ -63,7 +66,6 @@
|
|||||||
#include <crstate.hxx>
|
#include <crstate.hxx>
|
||||||
#include <comphelper/extract.hxx>
|
#include <comphelper/extract.hxx>
|
||||||
#include <comphelper/profilezone.hxx>
|
#include <comphelper/profilezone.hxx>
|
||||||
#include <comphelper/OUStringLiteralList.hxx>
|
|
||||||
#include <comphelper/sequence.hxx>
|
#include <comphelper/sequence.hxx>
|
||||||
#include <cppuhelper/supportsservice.hxx>
|
#include <cppuhelper/supportsservice.hxx>
|
||||||
#include <svx/scene3d.hxx>
|
#include <svx/scene3d.hxx>
|
||||||
@@ -2149,7 +2151,7 @@ uno::Sequence< OUString > SwXShape::getSupportedServiceNames()
|
|||||||
if (SvxShape* pSvxShape = GetSvxShape())
|
if (SvxShape* pSvxShape = GetSvxShape())
|
||||||
aSeq = pSvxShape->getSupportedServiceNames();
|
aSeq = pSvxShape->getSupportedServiceNames();
|
||||||
return comphelper::concatSequences(
|
return comphelper::concatSequences(
|
||||||
aSeq, comphelper::OUStringLiteralList({ "com.sun.star.drawing.Shape" }));
|
aSeq, std::initializer_list<OUStringLiteral>{ "com.sun.star.drawing.Shape" });
|
||||||
}
|
}
|
||||||
|
|
||||||
SvxShape* SwXShape::GetSvxShape()
|
SvxShape* SwXShape::GetSvxShape()
|
||||||
|
Reference in New Issue
Block a user