From 63baebc698d987a3b71be4fadafbb09ac14c7be7 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 6 Mar 2017 15:58:24 +0100 Subject: [PATCH] #1292 Fixed CppCheck Issues in AppFwk/cafProjectDataModel --- .../cafPdmChildArrayFieldHandleTest.cpp | 6 ++---- .../cafPdmCoreBasicTest.cpp | 15 +++++++------- .../cafPdmReferenceHelperTest.cpp | 3 ++- .../cafPdmCore/cafPdmObjectHandle.cpp | 2 +- .../cafPdmCore/cafPdmObjectHandle.h | 2 +- .../cafPdmCore/cafTristate.cpp | 8 -------- .../cafPdmCore/cafTristate.h | 1 - .../cafPdmUiCore/cafPdmUiEditorHandle.h | 2 +- .../cafPdmUiCore/cafPdmUiItem.h | 2 +- .../cafPdmUiCore/cafPdmUiOrdering.cpp | 2 +- .../cafPdmUiCore/cafPdmUiOrdering.h | 2 +- .../cafPdmUiCore/cafPdmUiTreeOrdering.cpp | 4 ++-- .../cafPdmUiCore/cafPdmUiTreeOrdering.h | 4 ++-- .../cafPdmAdvancedTemplateTest.cpp | 2 +- .../cafPdmXmlBasicTest.cpp | 3 ++- .../cafPdmBasicTest.cpp | 20 ++++++++----------- 16 files changed, 32 insertions(+), 46 deletions(-) diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmChildArrayFieldHandleTest.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmChildArrayFieldHandleTest.cpp index f3f592f3d4..e5e4046532 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmChildArrayFieldHandleTest.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmChildArrayFieldHandleTest.cpp @@ -97,8 +97,7 @@ TEST(ChildArrayFieldHandle, DerivedObjects) containerObj->derivedObjs.push_back(s1); containerObj->derivedObjs.push_back(s2); - SimpleObjDerived* myObj = NULL; - myObj = findObjectById(containerObj->derivedObjs.begin(), containerObj->derivedObjs.end(), 2); + SimpleObjDerived* myObj = findObjectById(containerObj->derivedObjs.begin(), containerObj->derivedObjs.end(), 2); EXPECT_EQ(s2, myObj); myObj = findObjectById(containerObj->derivedObjs.begin(), containerObj->derivedObjs.end(), -1); @@ -121,8 +120,7 @@ TEST(ChildArrayFieldHandle, DerivedOtherObjects) containerObj->derivedOtherObjs.push_back(s1); containerObj->derivedOtherObjs.push_back(s2); - SimpleObjDerivedOther* myObj = NULL; - myObj = findObjectById(containerObj->derivedOtherObjs.begin(), containerObj->derivedOtherObjs.end(), s2Id); + SimpleObjDerivedOther* myObj = findObjectById(containerObj->derivedOtherObjs.begin(), containerObj->derivedOtherObjs.end(), s2Id); EXPECT_EQ(s2, myObj); myObj = findObjectById(containerObj->derivedOtherObjs.begin(), containerObj->derivedOtherObjs.end(), -1); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmCoreBasicTest.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmCoreBasicTest.cpp index 06e0b352fb..b70ae0c460 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmCoreBasicTest.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmCoreBasicTest.cpp @@ -212,7 +212,7 @@ TEST(BaseTest, NormalPdmField) class A : public caf::PdmObjectHandle { public: - A(const std::vector& testValue) : field2(testValue), field3(field2) + explicit A(const std::vector& testValue) : field2(testValue), field3(field2) { this->addField(&field1, "field1"); this->addField(&field2, "field2"); @@ -440,7 +440,9 @@ TEST(BaseTest, PdmChildField) class A : public caf::PdmObjectHandle { public: - A(Child* a) :field2(a) + explicit A(Child* a) + : field2(a), + b(0) { this->addField(&field2, "field2"); } @@ -455,7 +457,6 @@ TEST(BaseTest, PdmChildField) }; { - Parent* parent = new Parent; Child* testValue = new Child; // Constructor assignment @@ -464,7 +465,7 @@ TEST(BaseTest, PdmChildField) // Guarded delete testValue; - EXPECT_EQ((Child*)0, a.field2); + EXPECT_EQ(static_cast(nullptr), a.field2); } { A a(NULL); @@ -492,13 +493,11 @@ TEST(BaseTest, PdmPtrField) InheritedDemoObj* ihd2 = new InheritedDemoObj; // Direct access - EXPECT_EQ((InheritedDemoObj*)NULL, ihd1->m_ptrField); - - InheritedDemoObj* accessedIhd = NULL; + EXPECT_EQ(static_cast(nullptr), ihd1->m_ptrField); // Assignment ihd1->m_ptrField = ihd1; - accessedIhd = ihd1->m_ptrField; + InheritedDemoObj* accessedIhd = ihd1->m_ptrField; EXPECT_EQ(ihd1, accessedIhd); ihd1->m_ptrField = caf::PdmPointer(ihd2); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmReferenceHelperTest.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmReferenceHelperTest.cpp index f8bed80aa1..8f7826653f 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmReferenceHelperTest.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests/cafPdmReferenceHelperTest.cpp @@ -16,7 +16,8 @@ class SimpleObj : public caf::PdmObjectHandle { public: - SimpleObj() : PdmObjectHandle() + SimpleObj() : PdmObjectHandle(), + m_doubleMember(0.0) { this->addField(&m_position, "m_position"); this->addField(&m_dir, "m_dir"); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.cpp index 2124871255..6eb207d9f0 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.cpp @@ -121,7 +121,7 @@ void PdmObjectHandle::addField(PdmFieldHandle* field, const QString& keyword) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -PdmFieldHandle* PdmObjectHandle::findField(const QString& keyword) +PdmFieldHandle* PdmObjectHandle::findField(const QString& keyword) const { std::vector fields; this->fields(fields); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h index fd5acd7370..b4ec6869f5 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h @@ -28,7 +28,7 @@ public: /// The registered fields contained in this PdmObject. void fields(std::vector& fields) const; - PdmFieldHandle* findField(const QString& keyword); + PdmFieldHandle* findField(const QString& keyword) const; /// The field referencing this object as a child PdmFieldHandle* parentField() const; diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.cpp index a916bdcbfb..a392d6627c 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.cpp @@ -11,14 +11,6 @@ caf::Tristate::Tristate() { } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void caf::Tristate::operator=(const Tristate& other) -{ - m_state = other.m_state; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.h index 8f9eec190c..6693ec32f5 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.h @@ -20,7 +20,6 @@ public: public: Tristate(); - void operator=(const Tristate& other); void operator=(const State& state); bool operator==(const Tristate& other) const; diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiEditorHandle.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiEditorHandle.h index 5e699b152e..fd9842f6f2 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiEditorHandle.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiEditorHandle.h @@ -97,7 +97,7 @@ private: class PdmUiProxyEditorHandle: public PdmUiEditorHandle { public: - PdmUiProxyEditorHandle(PdmUiEditorHandle* mainEditorHandle) : PdmUiEditorHandle() { m_mainEditorHandle = mainEditorHandle; } + explicit PdmUiProxyEditorHandle(PdmUiEditorHandle* mainEditorHandle) : PdmUiEditorHandle() { m_mainEditorHandle = mainEditorHandle; } virtual ~PdmUiProxyEditorHandle() {}; protected: // Interface to override: diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h index bedbe17367..59a66d94a2 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h @@ -137,7 +137,7 @@ bool PdmOptionItemInfo::findValues(const QList& optionList, Q for (int i = 0; i < valuesSelectedInField.size(); ++i) { std::list >::iterator it; - for (it = optionVariantAndIndexPairs.begin(); it != optionVariantAndIndexPairs.end(); it++) + for (it = optionVariantAndIndexPairs.begin(); it != optionVariantAndIndexPairs.end(); ++it) { if (PdmUiFieldSpecialization::isDataElementEqual(valuesSelectedInField[i], it->first)) { diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.cpp index 7bc8540cdb..4b9da8b5cf 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.cpp @@ -75,7 +75,7 @@ PdmUiGroup* PdmUiOrdering::addNewGroup(QString displayName) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool PdmUiOrdering::contains(const PdmUiItem* item) +bool PdmUiOrdering::contains(const PdmUiItem* item) const { for (size_t i = 0; i < m_ordering.size(); ++i) { diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h index 58f4c03e47..415b790673 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h @@ -70,7 +70,7 @@ public: void setForgetRemainingFields(bool val) { m_forgetRemainingFields = val; } const std::vector& uiItems() const { return m_ordering; } - bool contains(const PdmUiItem* item); + bool contains(const PdmUiItem* item) const; private: // Private copy constructor and assignment to prevent this. (The vectors below will make trouble) diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiTreeOrdering.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiTreeOrdering.cpp index dde47242b4..370a8e7deb 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiTreeOrdering.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiTreeOrdering.cpp @@ -71,7 +71,7 @@ void PdmUiTreeOrdering::add(PdmFieldHandle* field, QString uiConfigName) } else { - PdmUiTreeOrdering* child = new PdmUiTreeOrdering(this, field); + new PdmUiTreeOrdering(this, field); } } @@ -82,7 +82,7 @@ void PdmUiTreeOrdering::add(PdmObjectHandle* object) { assert(object); - PdmUiTreeOrdering* child = new PdmUiTreeOrdering(this, object); + new PdmUiTreeOrdering(this, object); } //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiTreeOrdering.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiTreeOrdering.h index 5ffd1f099b..c31608cdae 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiTreeOrdering.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiTreeOrdering.h @@ -63,8 +63,8 @@ class PdmUiTreeOrdering; class PdmUiTreeOrdering { public: - PdmUiTreeOrdering(PdmObjectHandle* pdmItem ); - PdmUiTreeOrdering(PdmFieldHandle* pdmField ); + explicit PdmUiTreeOrdering(PdmObjectHandle* pdmItem ); + explicit PdmUiTreeOrdering(PdmFieldHandle* pdmField ); PdmUiTreeOrdering(const QString & title, const QString& iconResourceName ); ~PdmUiTreeOrdering(); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXml_UnitTests/cafPdmAdvancedTemplateTest.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXml_UnitTests/cafPdmAdvancedTemplateTest.cpp index 7c8000f8c9..ae9acc4301 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXml_UnitTests/cafPdmAdvancedTemplateTest.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXml_UnitTests/cafPdmAdvancedTemplateTest.cpp @@ -28,7 +28,7 @@ public: CAF_PDM_XML_InitField(&m_name, "Name"); } - ItemPdmObject(QString name) : PdmObjectHandle(), PdmXmlObjectHandle(this, false) + explicit ItemPdmObject(QString name) : PdmObjectHandle(), PdmXmlObjectHandle(this, false) { CAF_PDM_XML_InitField(&m_name, "Name"); m_name = name; diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXml_UnitTests/cafPdmXmlBasicTest.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXml_UnitTests/cafPdmXmlBasicTest.cpp index ed388c2496..86078bacf8 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXml_UnitTests/cafPdmXmlBasicTest.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXml_UnitTests/cafPdmXmlBasicTest.cpp @@ -192,7 +192,8 @@ class SimpleObj : public caf::PdmObjectHandle, public caf::PdmXmlObjectHandle { CAF_PDM_XML_HEADER_INIT; public: - SimpleObj() : PdmObjectHandle(), PdmXmlObjectHandle(this, false) + SimpleObj() : PdmObjectHandle(), PdmXmlObjectHandle(this, false), + m_doubleMember(0.0) { CAF_PDM_XML_InitField(&m_position, "Position"); CAF_PDM_XML_InitField(&m_dir, "Dir"); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafProjectDataModel_UnitTests/cafPdmBasicTest.cpp b/Fwk/AppFwk/cafProjectDataModel/cafProjectDataModel_UnitTests/cafPdmBasicTest.cpp index 10723321b6..8c53376a39 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafProjectDataModel_UnitTests/cafPdmBasicTest.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafProjectDataModel_UnitTests/cafPdmBasicTest.cpp @@ -61,7 +61,8 @@ class SimpleObj: public caf::PdmObject { CAF_PDM_HEADER_INIT; public: - SimpleObj() : PdmObject() + SimpleObj() : PdmObject(), + m_doubleMember(0.0) { CAF_PDM_InitObject("SimpleObj", "", "Tooltip SimpleObj", "WhatsThis SimpleObj"); @@ -93,6 +94,7 @@ public: m_dir = other.m_dir; m_up = other.m_up; m_numbers = other.m_numbers; + m_doubleMember = other.m_doubleMember; } ~SimpleObj() {} @@ -751,31 +753,26 @@ TEST(BaseTest, PdmPointer) TEST(BaseTest, PdmObjectFactory) { { - SimpleObj* s = NULL; - s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("SimpleObj")); + SimpleObj* s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("SimpleObj")); EXPECT_TRUE(s != NULL); } { - DemoPdmObject* s = NULL; - s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("DemoPdmObject")); + DemoPdmObject* s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("DemoPdmObject")); EXPECT_TRUE(s != NULL); delete s; } { - InheritedDemoObj* s = NULL; - s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("InheritedDemoObj")); + InheritedDemoObj* s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("InheritedDemoObj")); EXPECT_TRUE(s != NULL); } { - caf::PdmDocument* s = NULL; - s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("PdmDocument")); + caf::PdmDocument* s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("PdmDocument")); EXPECT_TRUE(s != NULL); } { - caf::PdmObjectGroup* s = NULL; - s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("PdmObjectGroup")); + caf::PdmObjectGroup* s = dynamic_cast (caf::PdmDefaultObjectFactory::instance()->create("PdmObjectGroup")); EXPECT_TRUE(s != NULL); } @@ -959,7 +956,6 @@ TEST(BaseTest, PdmReferenceHelper) s3->m_position = 3000; InheritedDemoObj* ihd1 = new InheritedDemoObj; - caf::PdmChildArrayFieldHandle* listField = &(ihd1->m_simpleObjectsField); ihd1->m_simpleObjectsField.push_back(new SimpleObj); ihd1->m_simpleObjectsField.push_back(s1);