[Libreoffice-commits] core.git: compilerplugins/clang testtools/source
Stephan Bergmann
sbergman at redhat.com
Thu Apr 21 15:29:09 UTC 2016
compilerplugins/clang/implicitboolconversion.cxx | 39 +++++++++++++++++++
testtools/source/bridgetest/bridgetest.cxx | 47 ++++++++---------------
2 files changed, 57 insertions(+), 29 deletions(-)
New commits:
commit 8c423eeb49606087243fb6bbf31c0981c55dc773
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Apr 21 17:27:43 2016 +0200
Use Sequence ctor taking initializer_list
needed adapting loplugin:implicitboolconversion to not warn about
Sequence<sal_Bool> arBool({true, false, true});
Change-Id: I971918aab7c958ef8f1e4e0548a84314e95f8325
diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx
index 9fa073c..226f49d 100644
--- a/compilerplugins/clang/implicitboolconversion.cxx
+++ b/compilerplugins/clang/implicitboolconversion.cxx
@@ -293,6 +293,8 @@ public:
bool TraverseBinXorAssign(CompoundAssignOperator * expr);
+ bool TraverseCXXStdInitializerListExpr(CXXStdInitializerListExpr * expr);
+
bool TraverseReturnStmt(ReturnStmt * stmt);
bool TraverseFunctionDecl(FunctionDecl * decl);
@@ -766,6 +768,43 @@ bool ImplicitBoolConversion::TraverseBinXorAssign(CompoundAssignOperator * expr)
return bRet;
}
+bool ImplicitBoolConversion::TraverseCXXStdInitializerListExpr(
+ CXXStdInitializerListExpr * expr)
+{
+ // Must be some std::initializer_list<T>; check whether T is sal_Bool (i.e.,
+ // unsigned char) [TODO: check for real sal_Bool instead]:
+ auto t = expr->getType();
+ if (auto et = dyn_cast<ElaboratedType>(t)) {
+ t = et->desugar();
+ }
+ auto ts = t->getAs<TemplateSpecializationType>();
+ if (ts == nullptr
+ || !ts->getArg(0).getAsType()->isSpecificBuiltinType(
+ clang::BuiltinType::UChar))
+ {
+ return RecursiveASTVisitor::TraverseCXXStdInitializerListExpr(expr);
+ }
+ // Avoid warnings for code like
+ //
+ // Sequence<sal_Bool> arBool({true, false, true});
+ //
+ auto e = dyn_cast<InitListExpr>(
+ ignoreParenAndTemporaryMaterialization(expr->getSubExpr()));
+ if (e == nullptr) {
+ return RecursiveASTVisitor::TraverseCXXStdInitializerListExpr(expr);
+ }
+ nested.push(std::vector<ImplicitCastExpr const *>());
+ bool ret = RecursiveASTVisitor::TraverseCXXStdInitializerListExpr(expr);
+ assert(!nested.empty());
+ for (auto i: nested.top()) {
+ if (!std::find(e->begin(), e->end(), i)) {
+ reportWarning(i);
+ }
+ }
+ nested.pop();
+ return ret;
+}
+
bool ImplicitBoolConversion::TraverseReturnStmt(ReturnStmt * stmt) {
nested.push(std::vector<ImplicitCastExpr const *>());
bool bRet = RecursiveASTVisitor::TraverseReturnStmt(stmt);
diff --git a/testtools/source/bridgetest/bridgetest.cxx b/testtools/source/bridgetest/bridgetest.cxx
index bde1492..df7e87a 100644
--- a/testtools/source/bridgetest/bridgetest.cxx
+++ b/testtools/source/bridgetest/bridgetest.cxx
@@ -641,22 +641,8 @@ static bool performTest(
}
// Perform sequence tests (XBridgeTest2); create the sequence which is
// compared with the results:
- sal_Bool _arBool[] = { true, false, true };
- sal_Unicode _arChar[] = { 0x0065, 0x0066, 0x0067 };
- sal_Int8 _arByte[] = { 1, 2, -1 };
- sal_Int16 _arShort[] = { -0x8000, 1, 0x7FFF };
- sal_uInt16 _arUShort[] = { 0 , 1, 0xFFFF };
sal_Int32 _arLong[] = {
static_cast< sal_Int32 >(0x80000000), 1, 0x7FFFFFFF };
- sal_uInt32 _arULong[] = { 0, 1, 0xFFFFFFFF };
- sal_Int64 _arHyper[] = {
- static_cast< sal_Int64 >(SAL_CONST_INT64(0x8000000000000000)), 1,
- SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF) };
- sal_uInt64 _arUHyper[] = { 0, 1, SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF) };
- OUString _arString[] = {
- OUString("String 1"),
- OUString("String 2"),
- OUString("String 3") };
sal_Bool _aBool = true;
sal_Int32 _aInt = 0xBABEBABE;
float _aFloat = 3.14f;
@@ -668,7 +654,6 @@ static bool performTest(
_arObj[0] = new OWeakObject();
_arObj[1] = new OWeakObject();
_arObj[2] = new OWeakObject();
- TestEnum _arEnum[] = { TestEnum_ONE, TestEnum_TWO, TestEnum_CHECK };
TestElement _arStruct[3];
assign(
_arStruct[0], true, '@', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
@@ -689,23 +674,27 @@ static bool performTest(
TestEnum_CHECK, STRING_TEST_CONSTANT, _arObj[2],
Any(&_arObj[2], cppu::UnoType<XInterface>::get()));
{
- float _arFloat[] = { 1.1f, 2.2f, 3.3f };
- double _arDouble[] = { 1.11, 2.22, 3.33 };
- Sequence<sal_Bool> arBool(_arBool, 3);
- Sequence<sal_Unicode> arChar( _arChar, 3);
- Sequence<sal_Int8> arByte(_arByte, 3);
- Sequence<sal_Int16> arShort(_arShort, 3);
- Sequence<sal_uInt16> arUShort(_arUShort, 3);
+ Sequence<sal_Bool> arBool({true, false, true});
+ Sequence<sal_Unicode> arChar({0x0065, 0x0066, 0x0067});
+ Sequence<sal_Int8> arByte({1, 2, -1});
+ Sequence<sal_Int16> arShort({-0x8000, 1, 0x7FFF});
+ Sequence<sal_uInt16> arUShort({0 , 1, 0xFFFF});
Sequence<sal_Int32> arLong(_arLong, 3);
- Sequence<sal_uInt32> arULong(_arULong, 3);
- Sequence<sal_Int64> arHyper(_arHyper, 3);
- Sequence<sal_uInt64> arUHyper(_arUHyper, 3);
- Sequence<float> arFloat(_arFloat, 3);
- Sequence<double> arDouble(_arDouble, 3);
- Sequence<OUString> arString(_arString, 3);
+ Sequence<sal_uInt32> arULong({0, 1, 0xFFFFFFFF});
+ Sequence<sal_Int64> arHyper({
+ static_cast<sal_Int64>(SAL_CONST_INT64(0x8000000000000000)), 1,
+ SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF)});
+ Sequence<sal_uInt64> arUHyper({
+ 0, 1, SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF)});
+ Sequence<float> arFloat({1.1f, 2.2f, 3.3f});
+ Sequence<double> arDouble({1.11, 2.22, 3.33});
+ Sequence<OUString> arString({
+ OUString("String 1"), OUString("String 2"),
+ OUString("String 3")});
Sequence<Any> arAny(_arAny, 3);
Sequence<Reference<XInterface> > arObject(_arObj, 3);
- Sequence<TestEnum> arEnum(_arEnum, 3);
+ Sequence<TestEnum> arEnum({
+ TestEnum_ONE, TestEnum_TWO, TestEnum_CHECK});
Sequence<TestElement> arStruct(_arStruct, 3);
Sequence<Sequence<sal_Int32> > _arSeqLong2[3];
for (int j = 0; j != 3; ++j) {
More information about the Libreoffice-commits
mailing list