From ac30a4709ff225c8c93337ee61709b33d3772d76 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 8 Nov 2023 15:57:04 -0500 Subject: [PATCH] cpp-common/bt2: remove useless copy operations This patch removes useless copy constructors and assignment operators from many wrapper classes in `cpp-common/bt2` where the compiler generates some anyway. Also, return by value (like everywhere else) from pseudo copy operations. Signed-off-by: Philippe Proulx Change-Id: I9e5b5e956905681c3a834122b3f0ed8311b5a6ae Reviewed-on: https://review.lttng.org/c/babeltrace/+/11302 Reviewed-by: Simon Marchi --- src/cpp-common/bt2/borrowed-object.hpp | 6 +--- src/cpp-common/bt2/clock-class.hpp | 3 -- src/cpp-common/bt2/clock-snapshot.hpp | 11 ------- src/cpp-common/bt2/field-class.hpp | 42 ++++++++++++------------ src/cpp-common/bt2/field-path.hpp | 31 ----------------- src/cpp-common/bt2/field.hpp | 36 +++++++++----------- src/cpp-common/bt2/integer-range-set.hpp | 2 +- src/cpp-common/bt2/integer-range.hpp | 10 ------ src/cpp-common/bt2/message.hpp | 18 +++++----- src/cpp-common/bt2/trace-ir.hpp | 14 ++++---- src/cpp-common/bt2/value.hpp | 16 ++++----- 11 files changed, 62 insertions(+), 127 deletions(-) diff --git a/src/cpp-common/bt2/borrowed-object.hpp b/src/cpp-common/bt2/borrowed-object.hpp index 6b1f6e57..678fed82 100644 --- a/src/cpp-common/bt2/borrowed-object.hpp +++ b/src/cpp-common/bt2/borrowed-object.hpp @@ -87,10 +87,6 @@ protected: BT_ASSERT_DBG(libObjPtr); } - /* Default copy operations */ - BorrowedObject(const BorrowedObject&) noexcept = default; - BorrowedObject& operator=(const BorrowedObject&) noexcept = default; - /* * Generic "copy" constructor. * @@ -126,7 +122,7 @@ protected: * context in the compiler error message. */ template - _ThisBorrowedObject& operator=(const BorrowedObject& other) noexcept + _ThisBorrowedObject operator=(const BorrowedObject& other) noexcept { static_assert(_AssignableFromConst::val, "Don't assign a non-const wrapper from a const wrapper."); diff --git a/src/cpp-common/bt2/clock-class.hpp b/src/cpp-common/bt2/clock-class.hpp index 35ddfbfa..bd127dfa 100644 --- a/src/cpp-common/bt2/clock-class.hpp +++ b/src/cpp-common/bt2/clock-class.hpp @@ -72,9 +72,6 @@ public: { } - ClockClassOffset(const ClockClassOffset&) noexcept = default; - ClockClassOffset& operator=(const ClockClassOffset&) noexcept = default; - std::int64_t seconds() const noexcept { return _mSeconds; diff --git a/src/cpp-common/bt2/clock-snapshot.hpp b/src/cpp-common/bt2/clock-snapshot.hpp index ed30eaf5..190eb6a2 100644 --- a/src/cpp-common/bt2/clock-snapshot.hpp +++ b/src/cpp-common/bt2/clock-snapshot.hpp @@ -24,17 +24,6 @@ public: { } - ConstClockSnapshot(const ConstClockSnapshot& clkSnapshot) noexcept : - _ThisBorrowedObject {clkSnapshot} - { - } - - ConstClockSnapshot& operator=(const ConstClockSnapshot& clkSnapshot) noexcept - { - _ThisBorrowedObject::operator=(clkSnapshot); - return *this; - } - std::uint64_t value() const noexcept { return bt_clock_snapshot_get_value(this->libObjPtr()); diff --git a/src/cpp-common/bt2/field-class.hpp b/src/cpp-common/bt2/field-class.hpp index 95d3f8b2..13ac7b4f 100644 --- a/src/cpp-common/bt2/field-class.hpp +++ b/src/cpp-common/bt2/field-class.hpp @@ -184,7 +184,7 @@ public: } template - CommonFieldClass& operator=(const CommonFieldClass fc) noexcept + CommonFieldClass operator=(const CommonFieldClass fc) noexcept { _ThisBorrowedObject::operator=(fc); return *this; @@ -472,7 +472,7 @@ public: } template - CommonBitArrayFieldClass& + CommonBitArrayFieldClass operator=(const CommonBitArrayFieldClass fc) noexcept { _ThisCommonFieldClass::operator=(fc); @@ -552,7 +552,7 @@ public: } template - CommonIntegerFieldClass& operator=(const CommonIntegerFieldClass fc) noexcept + CommonIntegerFieldClass operator=(const CommonIntegerFieldClass fc) noexcept { _ThisCommonFieldClass::operator=(fc); return *this; @@ -686,7 +686,7 @@ public: { } - ConstEnumerationFieldClassMapping& + ConstEnumerationFieldClassMapping operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept { _ThisBorrowedObject::operator=(mapping); @@ -793,7 +793,7 @@ public: } template - CommonBaseEnumerationFieldClass& + CommonBaseEnumerationFieldClass operator=(const CommonBaseEnumerationFieldClass fc) noexcept { _ThisCommonIntegerFieldClass::operator=(fc); @@ -842,7 +842,7 @@ public: } template - CommonEnumerationFieldClass& + CommonEnumerationFieldClass operator=(const CommonEnumerationFieldClass fc) noexcept { CommonEnumerationFieldClass::operator=(fc); @@ -1013,7 +1013,7 @@ public: } template - CommonStructureFieldClassMember& + CommonStructureFieldClassMember operator=(const CommonStructureFieldClassMember fc) noexcept { _ThisBorrowedObject::operator=(fc); @@ -1143,7 +1143,7 @@ public: } template - CommonStructureFieldClass& operator=(const CommonStructureFieldClass fc) noexcept + CommonStructureFieldClass operator=(const CommonStructureFieldClass fc) noexcept { _ThisCommonFieldClass::operator=(fc); return *this; @@ -1289,7 +1289,7 @@ public: } template - CommonArrayFieldClass& operator=(const CommonArrayFieldClass fc) noexcept + CommonArrayFieldClass operator=(const CommonArrayFieldClass fc) noexcept { _ThisCommonFieldClass::operator=(fc); return *this; @@ -1358,7 +1358,7 @@ public: } template - CommonStaticArrayFieldClass& + CommonStaticArrayFieldClass operator=(const CommonStaticArrayFieldClass fc) noexcept { _ThisCommonArrayFieldClass::operator=(fc); @@ -1428,7 +1428,7 @@ public: } template - CommonDynamicArrayWithLengthFieldClass& + CommonDynamicArrayWithLengthFieldClass operator=(const CommonDynamicArrayWithLengthFieldClass fc) noexcept { _ThisCommonArrayFieldClass::operator=(fc); @@ -1530,7 +1530,7 @@ public: } template - CommonOptionFieldClass& operator=(const CommonOptionFieldClass fc) noexcept + CommonOptionFieldClass operator=(const CommonOptionFieldClass fc) noexcept { _ThisCommonFieldClass::operator=(fc); return *this; @@ -1603,7 +1603,7 @@ public: } template - CommonOptionWithSelectorFieldClass& + CommonOptionWithSelectorFieldClass operator=(const CommonOptionWithSelectorFieldClass fc) noexcept { _ThisCommonOptionFieldClass::operator=(fc); @@ -1677,7 +1677,7 @@ public: } template - CommonOptionWithBoolSelectorFieldClass& + CommonOptionWithBoolSelectorFieldClass operator=(const CommonOptionWithBoolSelectorFieldClass fc) noexcept { _ThisCommonOptionWithSelectorFieldClass::operator=(fc); @@ -1782,7 +1782,7 @@ public: } template - CommonOptionWithIntegerSelectorFieldClass& + CommonOptionWithIntegerSelectorFieldClass operator=(const CommonOptionWithIntegerSelectorFieldClass fc) noexcept { _ThisCommonOptionWithSelectorFieldClass::operator=(fc); @@ -1911,7 +1911,7 @@ public: } template - CommonVariantFieldClassOption& + CommonVariantFieldClassOption operator=(const CommonVariantFieldClassOption fc) noexcept { _ThisBorrowedObject::operator=(fc); @@ -2058,7 +2058,7 @@ public: } template - ConstVariantWithIntegerSelectorFieldClassOption& + ConstVariantWithIntegerSelectorFieldClassOption operator=(const ConstVariantWithIntegerSelectorFieldClassOption fc) noexcept { _ThisBorrowedObject::operator=(fc); @@ -2165,7 +2165,7 @@ public: } template - CommonVariantFieldClass& operator=(const CommonVariantFieldClass fc) noexcept + CommonVariantFieldClass operator=(const CommonVariantFieldClass fc) noexcept { _ThisCommonFieldClass::operator=(fc); return *this; @@ -2267,7 +2267,7 @@ public: } template - CommonVariantWithoutSelectorFieldClass& + CommonVariantWithoutSelectorFieldClass operator=(const CommonVariantWithoutSelectorFieldClass fc) noexcept { _ThisCommonVariantFieldClass::operator=(fc); @@ -2420,7 +2420,7 @@ public: } template - CommonVariantWithSelectorFieldClass& + CommonVariantWithSelectorFieldClass operator=(const CommonVariantWithSelectorFieldClass fc) noexcept { _ThisCommonVariantFieldClass::operator=(fc); @@ -2481,7 +2481,7 @@ public: } template - CommonVariantWithIntegerSelectorFieldClass& + CommonVariantWithIntegerSelectorFieldClass operator=(const CommonVariantWithIntegerSelectorFieldClass fc) noexcept { _ThisCommonVariantWithSelectorFieldClass::operator=(fc); diff --git a/src/cpp-common/bt2/field-path.hpp b/src/cpp-common/bt2/field-path.hpp index 69f48455..300b7376 100644 --- a/src/cpp-common/bt2/field-path.hpp +++ b/src/cpp-common/bt2/field-path.hpp @@ -36,16 +36,6 @@ public: { } - ConstFieldPathItem(const ConstFieldPathItem& fpItem) noexcept : _ThisBorrowedObject {fpItem} - { - } - - ConstFieldPathItem& operator=(const ConstFieldPathItem& fpItem) noexcept - { - _ThisBorrowedObject::operator=(fpItem); - return *this; - } - FieldPathItemType type() const noexcept { return static_cast(this->_libType()); @@ -84,17 +74,6 @@ public: BT_ASSERT_DBG(this->isIndex()); } - ConstIndexFieldPathItem(const ConstIndexFieldPathItem& fpItem) noexcept : - ConstFieldPathItem {fpItem} - { - } - - ConstIndexFieldPathItem& operator=(const ConstIndexFieldPathItem& fpItem) noexcept - { - ConstFieldPathItem::operator=(fpItem); - return *this; - } - std::uint64_t index() const noexcept { return bt_field_path_item_index_get_index(this->libObjPtr()); @@ -142,16 +121,6 @@ public: { } - ConstFieldPath(const ConstFieldPath& fieldPath) noexcept : _ThisBorrowedObject {fieldPath} - { - } - - ConstFieldPath& operator=(const ConstFieldPath& fieldPath) noexcept - { - _ThisBorrowedObject::operator=(fieldPath); - return *this; - } - Scope rootScope() const noexcept { return static_cast(bt_field_path_get_root_scope(this->libObjPtr())); diff --git a/src/cpp-common/bt2/field.hpp b/src/cpp-common/bt2/field.hpp index b69295b2..cb9359e7 100644 --- a/src/cpp-common/bt2/field.hpp +++ b/src/cpp-common/bt2/field.hpp @@ -115,7 +115,7 @@ public: } template - _ThisCommonField& operator=(const CommonField val) noexcept + _ThisCommonField operator=(const CommonField val) noexcept { _ThisBorrowedObject::operator=(val); return *this; @@ -272,7 +272,7 @@ public: } template - CommonBoolField& operator=(const CommonBoolField val) noexcept + CommonBoolField operator=(const CommonBoolField val) noexcept { _ThisCommonField::operator=(val); return *this; @@ -346,7 +346,7 @@ public: } template - CommonBitArrayField& operator=(const CommonBitArrayField val) noexcept + CommonBitArrayField operator=(const CommonBitArrayField val) noexcept { _ThisCommonField::operator=(val); return *this; @@ -438,7 +438,7 @@ public: } template - _ThisCommonUnsignedIntegerField& + _ThisCommonUnsignedIntegerField operator=(const CommonUnsignedIntegerField val) noexcept { _ThisCommonField::operator=(val); @@ -524,7 +524,7 @@ public: } template - _ThisCommonSignedIntegerField& + _ThisCommonSignedIntegerField operator=(const CommonSignedIntegerField val) noexcept { _ThisCommonField::operator=(val); @@ -593,12 +593,6 @@ public: { } - EnumerationFieldClassMappingLabels(const EnumerationFieldClassMappingLabels&) noexcept = - default; - - EnumerationFieldClassMappingLabels& - operator=(const EnumerationFieldClassMappingLabels&) noexcept = default; - std::uint64_t length() const noexcept { return _mLen; @@ -639,7 +633,7 @@ public: } template - CommonUnsignedEnumerationField& + CommonUnsignedEnumerationField operator=(const CommonUnsignedEnumerationField val) noexcept { _ThisCommonUnsignedIntegerField::operator=(val); @@ -718,7 +712,7 @@ public: } template - CommonSignedEnumerationField& + CommonSignedEnumerationField operator=(const CommonSignedEnumerationField val) noexcept { _ThisCommonSignedIntegerField::operator=(val); @@ -797,7 +791,7 @@ public: } template - CommonSinglePrecisionRealField& + CommonSinglePrecisionRealField operator=(const CommonSinglePrecisionRealField val) noexcept { _ThisCommonField::operator=(val); @@ -875,7 +869,7 @@ public: } template - CommonDoublePrecisionRealField& + CommonDoublePrecisionRealField operator=(const CommonDoublePrecisionRealField val) noexcept { _ThisCommonField::operator=(val); @@ -950,7 +944,7 @@ public: } template - CommonStringField& operator=(const CommonStringField val) noexcept + CommonStringField operator=(const CommonStringField val) noexcept { _ThisCommonField::operator=(val); return *this; @@ -1097,7 +1091,7 @@ public: } template - CommonStructureField& operator=(const CommonStructureField val) noexcept + CommonStructureField operator=(const CommonStructureField val) noexcept { _ThisCommonField::operator=(val); return *this; @@ -1213,7 +1207,7 @@ public: } template - _ThisCommonArrayField& operator=(const CommonArrayField val) noexcept + _ThisCommonArrayField operator=(const CommonArrayField val) noexcept { _ThisCommonField::operator=(val); return *this; @@ -1284,7 +1278,7 @@ public: } template - CommonDynamicArrayField& + CommonDynamicArrayField operator=(const CommonDynamicArrayField val) noexcept { _ThisCommonArrayField::operator=(val); @@ -1382,7 +1376,7 @@ public: } template - CommonOptionField& operator=(const CommonOptionField val) noexcept + CommonOptionField operator=(const CommonOptionField val) noexcept { _ThisCommonField::operator=(val); return *this; @@ -1491,7 +1485,7 @@ public: } template - CommonVariantField& operator=(const CommonVariantField val) noexcept + CommonVariantField operator=(const CommonVariantField val) noexcept { _ThisCommonField::operator=(val); return *this; diff --git a/src/cpp-common/bt2/integer-range-set.hpp b/src/cpp-common/bt2/integer-range-set.hpp index 07de9431..1cfbfc3a 100644 --- a/src/cpp-common/bt2/integer-range-set.hpp +++ b/src/cpp-common/bt2/integer-range-set.hpp @@ -171,7 +171,7 @@ public: } template - CommonIntegerRangeSet& operator=(const CommonIntegerRangeSet rangeSet) noexcept + CommonIntegerRangeSet operator=(const CommonIntegerRangeSet rangeSet) noexcept { _ThisBorrowedObject::operator=(rangeSet); return *this; diff --git a/src/cpp-common/bt2/integer-range.hpp b/src/cpp-common/bt2/integer-range.hpp index aafc22e5..026e1d52 100644 --- a/src/cpp-common/bt2/integer-range.hpp +++ b/src/cpp-common/bt2/integer-range.hpp @@ -82,16 +82,6 @@ public: { } - ConstIntegerRange(const ConstIntegerRange& range) noexcept : _ThisBorrowedObject {range} - { - } - - ConstIntegerRange& operator=(const ConstIntegerRange& range) noexcept - { - _ThisBorrowedObject::operator=(range); - return *this; - } - bool operator==(const ConstIntegerRange& other) const noexcept { return internal::ConstIntegerRangeSpec::isEqual(this->libObjPtr(), diff --git a/src/cpp-common/bt2/message.hpp b/src/cpp-common/bt2/message.hpp index 1de0c481..ff0240d2 100644 --- a/src/cpp-common/bt2/message.hpp +++ b/src/cpp-common/bt2/message.hpp @@ -101,7 +101,7 @@ public: } template - _ThisCommonMessage& operator=(const CommonMessage val) noexcept + _ThisCommonMessage operator=(const CommonMessage val) noexcept { _ThisBorrowedObject::operator=(val); return *this; @@ -248,7 +248,7 @@ public: } template - CommonStreamBeginningMessage& + CommonStreamBeginningMessage operator=(const CommonStreamBeginningMessage val) noexcept { _ThisCommonMessage::operator=(val); @@ -363,7 +363,7 @@ public: } template - CommonStreamEndMessage& + CommonStreamEndMessage operator=(const CommonStreamEndMessage val) noexcept { _ThisCommonMessage::operator=(val); @@ -477,7 +477,7 @@ public: } template - CommonPacketBeginningMessage& + CommonPacketBeginningMessage operator=(const CommonPacketBeginningMessage val) noexcept { _ThisCommonMessage::operator=(val); @@ -587,7 +587,7 @@ public: } template - CommonPacketEndMessage& + CommonPacketEndMessage operator=(const CommonPacketEndMessage val) noexcept { _ThisCommonMessage::operator=(val); @@ -696,7 +696,7 @@ public: } template - CommonEventMessage& operator=(const CommonEventMessage val) noexcept + CommonEventMessage operator=(const CommonEventMessage val) noexcept { _ThisCommonMessage::operator=(val); return *this; @@ -796,7 +796,7 @@ public: } template - CommonDiscardedEventsMessage& + CommonDiscardedEventsMessage operator=(const CommonDiscardedEventsMessage val) noexcept { _ThisCommonMessage::operator=(val); @@ -927,7 +927,7 @@ public: } template - CommonDiscardedPacketsMessage& + CommonDiscardedPacketsMessage operator=(const CommonDiscardedPacketsMessage val) noexcept { _ThisCommonMessage::operator=(val); @@ -1035,7 +1035,7 @@ public: } template - CommonMessageIteratorInactivityMessage& + CommonMessageIteratorInactivityMessage operator=(const CommonMessageIteratorInactivityMessage val) noexcept { _ThisCommonMessage::operator=(val); diff --git a/src/cpp-common/bt2/trace-ir.hpp b/src/cpp-common/bt2/trace-ir.hpp index b5557d7d..14863e18 100644 --- a/src/cpp-common/bt2/trace-ir.hpp +++ b/src/cpp-common/bt2/trace-ir.hpp @@ -151,7 +151,7 @@ public: } template - CommonEvent& operator=(const CommonEvent event) noexcept + CommonEvent operator=(const CommonEvent event) noexcept { _ThisBorrowedObject::operator=(event); return *this; @@ -292,7 +292,7 @@ public: } template - CommonPacket& operator=(const CommonPacket packet) noexcept + CommonPacket operator=(const CommonPacket packet) noexcept { _ThisBorrowedObject::operator=(packet); return *this; @@ -444,7 +444,7 @@ public: } template - CommonStream& operator=(const CommonStream stream) noexcept + CommonStream operator=(const CommonStream stream) noexcept { _ThisBorrowedObject::operator=(stream); return *this; @@ -658,7 +658,7 @@ public: } template - CommonTrace& operator=(const CommonTrace trace) noexcept + CommonTrace operator=(const CommonTrace trace) noexcept { _ThisBorrowedObject::operator=(trace); return *this; @@ -977,7 +977,7 @@ public: } template - CommonEventClass& operator=(const CommonEventClass eventClass) noexcept + CommonEventClass operator=(const CommonEventClass eventClass) noexcept { _ThisBorrowedObject::operator=(eventClass); return *this; @@ -1302,7 +1302,7 @@ public: } template - CommonStreamClass& operator=(const CommonStreamClass streamClass) noexcept + CommonStreamClass operator=(const CommonStreamClass streamClass) noexcept { _ThisBorrowedObject::operator=(streamClass); return *this; @@ -1731,7 +1731,7 @@ public: } template - CommonTraceClass& operator=(const CommonTraceClass traceClass) noexcept + CommonTraceClass operator=(const CommonTraceClass traceClass) noexcept { _ThisBorrowedObject::operator=(traceClass); return *this; diff --git a/src/cpp-common/bt2/value.hpp b/src/cpp-common/bt2/value.hpp index fe5a434d..cfbc92b5 100644 --- a/src/cpp-common/bt2/value.hpp +++ b/src/cpp-common/bt2/value.hpp @@ -129,7 +129,7 @@ public: } template - _ThisCommonValue& operator=(const CommonValue val) noexcept + _ThisCommonValue operator=(const CommonValue val) noexcept { _ThisBorrowedObject::operator=(val); return *this; @@ -410,7 +410,7 @@ public: } template - CommonNullValue& operator=(const CommonNullValue val) noexcept + CommonNullValue operator=(const CommonNullValue val) noexcept { _ThisCommonValue::operator=(val); return *this; @@ -480,7 +480,7 @@ public: } template - CommonBoolValue& operator=(const CommonBoolValue val) noexcept + CommonBoolValue operator=(const CommonBoolValue val) noexcept { _ThisCommonValue::operator=(val); return *this; @@ -569,7 +569,7 @@ public: } template - CommonUnsignedIntegerValue& + CommonUnsignedIntegerValue operator=(const CommonUnsignedIntegerValue val) noexcept { _ThisCommonValue::operator=(val); @@ -749,7 +749,7 @@ public: } template - CommonRealValue& operator=(const CommonRealValue val) noexcept + CommonRealValue operator=(const CommonRealValue val) noexcept { _ThisCommonValue::operator=(val); return *this; @@ -841,7 +841,7 @@ public: } template - CommonStringValue& operator=(const CommonStringValue val) noexcept + CommonStringValue operator=(const CommonStringValue val) noexcept { _ThisCommonValue::operator=(val); return *this; @@ -962,7 +962,7 @@ public: } template - CommonArrayValue& operator=(const CommonArrayValue val) noexcept + CommonArrayValue operator=(const CommonArrayValue val) noexcept { _ThisCommonValue::operator=(val); return *this; @@ -1265,7 +1265,7 @@ public: } template - CommonMapValue& operator=(const CommonMapValue val) noexcept + CommonMapValue operator=(const CommonMapValue val) noexcept { _ThisCommonValue::operator=(val); return *this; -- 2.34.1