From 70f8f80d9b43079234b97bc0212dd45638039b79 Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Sun, 7 May 2023 16:53:50 +0100 Subject: [PATCH] Fix clang-tidy performance-unnecessary-copy-initialization warnings --- examples/tcp/dctcp-example.cc | 9 +++----- examples/wireless/wifi-adhoc.cc | 3 +-- examples/wireless/wifi-clear-channel-cmu.cc | 3 +-- examples/wireless/wifi-multirate.cc | 3 +-- .../test/attribute-container-test-suite.cc | 6 ++---- src/core/test/simulator-test-suite.cc | 4 ++++ src/internet/model/ipv6-address-generator.cc | 3 +-- src/internet/model/tcp-socket-base.cc | 6 +----- src/lte/test/test-lte-x2-handover-measures.cc | 5 ++--- src/mobility/helper/ns2-mobility-helper.cc | 3 +-- src/network/test/packet-test-suite.cc | 4 ++++ src/wifi/model/he/he-ppdu.cc | 5 ++--- src/wifi/test/channel-access-manager-test.cc | 6 +++--- src/wimax/model/bs-uplink-scheduler-mbqos.cc | 2 +- src/wimax/model/dl-mac-messages.cc | 20 ++++-------------- src/wimax/model/ofdm-downlink-frame-prefix.cc | 10 ++------- src/wimax/model/ul-mac-messages.cc | 21 +++++-------------- 17 files changed, 38 insertions(+), 75 deletions(-) diff --git a/examples/tcp/dctcp-example.cc b/examples/tcp/dctcp-example.cc index 0d5e147e2..9d8e080ee 100644 --- a/examples/tcp/dctcp-example.cc +++ b/examples/tcp/dctcp-example.cc @@ -301,8 +301,6 @@ main(int argc, char* argv[]) Time startTime = Seconds(0); Time stopTime = flowStartupWindow + convergenceTime + measurementWindow; - Time clientStartTime = startTime; - rxS1R1Bytes.reserve(10); rxS2R2Bytes.reserve(20); rxS3R1Bytes.reserve(10); @@ -493,7 +491,7 @@ main(int argc, char* argv[]) AddressValue remoteAddress(InetSocketAddress(ipR2T2[i].GetAddress(0), port)); clientHelper1.SetAttribute("Remote", remoteAddress); clientApps1.Add(clientHelper1.Install(S2.Get(i))); - clientApps1.Start(i * flowStartupWindow / 20 + clientStartTime + MilliSeconds(i * 5)); + clientApps1.Start(i * flowStartupWindow / 20 + startTime + MilliSeconds(i * 5)); clientApps1.Stop(stopTime); } @@ -534,13 +532,12 @@ main(int argc, char* argv[]) if (i < 10) { clientApps1.Add(clientHelper1.Install(S1.Get(i))); - clientApps1.Start(i * flowStartupWindow / 10 + clientStartTime + MilliSeconds(i * 5)); + clientApps1.Start(i * flowStartupWindow / 10 + startTime + MilliSeconds(i * 5)); } else { clientApps1.Add(clientHelper1.Install(S3.Get(i - 10))); - clientApps1.Start((i - 10) * flowStartupWindow / 10 + clientStartTime + - MilliSeconds(i * 5)); + clientApps1.Start((i - 10) * flowStartupWindow / 10 + startTime + MilliSeconds(i * 5)); } clientApps1.Stop(stopTime); diff --git a/examples/wireless/wifi-adhoc.cc b/examples/wireless/wifi-adhoc.cc index e65724382..37fc872c5 100644 --- a/examples/wireless/wifi-adhoc.cc +++ b/examples/wireless/wifi-adhoc.cc @@ -175,8 +175,7 @@ Experiment::Run(const WifiHelper& wifi, YansWifiPhyHelper phy = wifiPhy; phy.SetChannel(wifiChannel.Create()); - WifiMacHelper mac = wifiMac; - NetDeviceContainer devices = wifi.Install(phy, mac, c); + NetDeviceContainer devices = wifi.Install(phy, wifiMac, c); MobilityHelper mobility; Ptr positionAlloc = CreateObject(); diff --git a/examples/wireless/wifi-clear-channel-cmu.cc b/examples/wireless/wifi-clear-channel-cmu.cc index 4b245270f..4b4f308a2 100644 --- a/examples/wireless/wifi-clear-channel-cmu.cc +++ b/examples/wireless/wifi-clear-channel-cmu.cc @@ -183,8 +183,7 @@ Experiment::Run(const WifiHelper& wifi, YansWifiPhyHelper phy = wifiPhy; phy.SetChannel(wifiChannel.Create()); - WifiMacHelper mac = wifiMac; - NetDeviceContainer devices = wifi.Install(phy, mac, c); + NetDeviceContainer devices = wifi.Install(phy, wifiMac, c); MobilityHelper mobility; Ptr positionAlloc = CreateObject(); diff --git a/examples/wireless/wifi-multirate.cc b/examples/wireless/wifi-multirate.cc index 0d8f0a65d..fd0a224a6 100644 --- a/examples/wireless/wifi-multirate.cc +++ b/examples/wireless/wifi-multirate.cc @@ -505,8 +505,7 @@ Experiment::Run(const WifiHelper& wifi, YansWifiPhyHelper phy = wifiPhy; phy.SetChannel(wifiChannel.Create()); - WifiMacHelper mac = wifiMac; - NetDeviceContainer devices = wifi.Install(phy, mac, c); + NetDeviceContainer devices = wifi.Install(phy, wifiMac, c); OlsrHelper olsr; Ipv4StaticRoutingHelper staticRouting; diff --git a/src/core/test/attribute-container-test-suite.cc b/src/core/test/attribute-container-test-suite.cc index fb12e2d08..5bd5175fe 100644 --- a/src/core/test/attribute-container-test-suite.cc +++ b/src/core/test/attribute-container-test-suite.cc @@ -376,8 +376,7 @@ AttributeContainerSerializationTestCase::DoRun() NS_TEST_ASSERT_MSG_EQ(attr.GetN(), 6, "Incorrect container size"); std::string reserialized = attr.SerializeToString(checker); - std::string canonical = strings; - NS_TEST_ASSERT_MSG_EQ(reserialized, canonical, "Reserialization failed"); + NS_TEST_ASSERT_MSG_EQ(reserialized, strings, "Reserialization failed"); } { @@ -394,8 +393,7 @@ AttributeContainerSerializationTestCase::DoRun() NS_TEST_ASSERT_MSG_EQ(attr.GetN(), 3, "Incorrect container size"); std::string reserialized = attr.SerializeToString(checker); - std::string canonical = pairs; - NS_TEST_ASSERT_MSG_EQ(reserialized, canonical, "Reserealization failed"); + NS_TEST_ASSERT_MSG_EQ(reserialized, pairs, "Reserealization failed"); } } diff --git a/src/core/test/simulator-test-suite.cc b/src/core/test/simulator-test-suite.cc index 178bc71f1..e2ff55969 100644 --- a/src/core/test/simulator-test-suite.cc +++ b/src/core/test/simulator-test-suite.cc @@ -171,7 +171,11 @@ SimulatorEventsTestCase::DoRun() NS_TEST_EXPECT_MSG_EQ(m_d, true, "Event D did not run ?"); EventId anId = Simulator::ScheduleNow(&SimulatorEventsTestCase::Eventfoo0, this); + + // Test copy assignment operator + // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) EventId anotherId = anId; + NS_TEST_EXPECT_MSG_EQ(!(anId.IsExpired() || anotherId.IsExpired()), true, "Event should not have expired yet."); diff --git a/src/internet/model/ipv6-address-generator.cc b/src/internet/model/ipv6-address-generator.cc index ead3de1fe..c01efafda 100644 --- a/src/internet/model/ipv6-address-generator.cc +++ b/src/internet/model/ipv6-address-generator.cc @@ -605,9 +605,8 @@ Ipv6AddressGeneratorImpl::IsNetworkAllocated(const Ipv6Address address, const Ip { NS_LOG_FUNCTION(this << address << prefix); - Ipv6Address addr = address; NS_ABORT_MSG_UNLESS( - address == addr.CombinePrefix(prefix), + address == address.CombinePrefix(prefix), "Ipv6AddressGeneratorImpl::IsNetworkAllocated(): network address and mask don't match " << address << " " << prefix); diff --git a/src/internet/model/tcp-socket-base.cc b/src/internet/model/tcp-socket-base.cc index cf7a80ca0..8c495905f 100644 --- a/src/internet/model/tcp-socket-base.cc +++ b/src/internet/model/tcp-socket-base.cc @@ -1596,13 +1596,9 @@ void TcpSocketBase::ReadOptions(const TcpHeader& tcpHeader, uint32_t* bytesSacked) { NS_LOG_FUNCTION(this << tcpHeader); - TcpHeader::TcpOptionList::const_iterator it; - const TcpHeader::TcpOptionList options = tcpHeader.GetOptionList(); - for (it = options.begin(); it != options.end(); ++it) + for (const auto& option : tcpHeader.GetOptionList()) { - const Ptr option = (*it); - // Check only for ACK options here switch (option->GetKind()) { diff --git a/src/lte/test/test-lte-x2-handover-measures.cc b/src/lte/test/test-lte-x2-handover-measures.cc index f2cd57d09..cf32f7a95 100644 --- a/src/lte/test/test-lte-x2-handover-measures.cc +++ b/src/lte/test/test-lte-x2-handover-measures.cc @@ -565,13 +565,12 @@ LteX2HandoverMeasuresTestCase::DoRun() ueDevices.Get(checkPointEventIt->ueDeviceIndex), enbDevices.Get(checkPointEventIt->enbDeviceIndex)); - Time saveStatsTime = checkPointTime; - Simulator::Schedule(saveStatsTime, + Simulator::Schedule(checkPointTime, &LteX2HandoverMeasuresTestCase::SaveStats, this, checkPointEventIt->ueDeviceIndex); - Time checkStats = saveStatsTime + m_statsDuration; + Time checkStats = checkPointTime + m_statsDuration; Simulator::Schedule(checkStats, &LteX2HandoverMeasuresTestCase::CheckStats, this, diff --git a/src/mobility/helper/ns2-mobility-helper.cc b/src/mobility/helper/ns2-mobility-helper.cc index eee8221aa..05ed8e967 100644 --- a/src/mobility/helper/ns2-mobility-helper.cc +++ b/src/mobility/helper/ns2-mobility-helper.cc @@ -622,8 +622,7 @@ IsVal(const std::string& str, T& ret) } else if (IsNumber(str)) { - std::string s2 = str; - std::istringstream s(s2); + std::istringstream s(str); s >> ret; return true; } diff --git a/src/network/test/packet-test-suite.cc b/src/network/test/packet-test-suite.cc index c7b8a7b04..0034598b0 100644 --- a/src/network/test/packet-test-suite.cc +++ b/src/network/test/packet-test-suite.cc @@ -1119,11 +1119,15 @@ PacketTagListTest::DoRun() { // Copy ctor, assignment std::cout << GetName() << "check copy and assignment" << std::endl; { + // Test copy constructor + // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) PacketTagList ptl(ref); CheckRefList(ref, "copy ctor orig"); CheckRefList(ptl, "copy ctor copy"); } { + // Test copy constructor + // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) PacketTagList ptl = ref; CheckRefList(ref, "assignment orig"); CheckRefList(ptl, "assignment copy"); diff --git a/src/wifi/model/he/he-ppdu.cc b/src/wifi/model/he/he-ppdu.cc index c02121583..7331585e7 100644 --- a/src/wifi/model/he/he-ppdu.cc +++ b/src/wifi/model/he/he-ppdu.cc @@ -202,10 +202,9 @@ void HePpdu::SetHeMuUserInfos(WifiTxVector& txVector, const HeSigHeader& heSig) const { WifiTxVector::HeMuUserInfoMap userInfos{}; - const auto contentChannels = heSig.GetHeSigBContentChannels(); - const auto ruAllocation = heSig.GetRuAllocation(); + const auto& ruAllocation = heSig.GetRuAllocation(); auto contentChannelIndex = 0; - for (const auto& contentChannel : contentChannels) + for (const auto& contentChannel : heSig.GetHeSigBContentChannels()) { auto numRusLeft = 0; auto ruAllocIndex = contentChannelIndex; diff --git a/src/wifi/test/channel-access-manager-test.cc b/src/wifi/test/channel-access-manager-test.cc index e82a1da29..6ad09b8ae 100644 --- a/src/wifi/test/channel-access-manager-test.cc +++ b/src/wifi/test/channel-access-manager-test.cc @@ -1440,9 +1440,9 @@ LargestIdlePrimaryChannelTest::RunOne(uint16_t chWidth, WifiChannelListType busy // At RX end, we check the status of the channel during the interval following // the CCA_BUSY period and preceding RX start. The entire operating channel is idle. - Time checkTime4 = checkTime3; + const Time& checkTime4 = checkTime3; Simulator::Schedule(checkTime4 - start, [=]() { - Time interval4 = ccaBusyRxInterval; + const Time& interval4 = ccaBusyRxInterval; Time end4 = checkTime4 - rxDuration; NS_TEST_EXPECT_MSG_EQ(m_cam->GetLargestIdlePrimaryChannel(interval4, end4), chWidth, @@ -1465,7 +1465,7 @@ LargestIdlePrimaryChannelTest::RunOne(uint16_t chWidth, WifiChannelListType busy }); // After RX end, no channel is idle if the interval overlaps the RX period - Time checkTime6 = checkTime5; + const Time& checkTime6 = checkTime5; Simulator::Schedule(checkTime6 - start, [=]() { Time interval6 = interval5 + rxDuration / 2; NS_TEST_EXPECT_MSG_EQ(m_cam->GetLargestIdlePrimaryChannel(interval6, checkTime6), diff --git a/src/wimax/model/bs-uplink-scheduler-mbqos.cc b/src/wimax/model/bs-uplink-scheduler-mbqos.cc index c702df38a..85e4b8eca 100644 --- a/src/wimax/model/bs-uplink-scheduler-mbqos.cc +++ b/src/wimax/model/bs-uplink-scheduler-mbqos.cc @@ -1172,7 +1172,7 @@ UplinkSchedulerMBQoS::ProcessBandwidthRequest(const BandwidthRequestHeader& bwRe Time deadline = DetermineDeadline(serviceFlow); Time currentTime = Simulator::Now(); - Time period = deadline; // So that deadline is properly updated.. + const Time& period = deadline; // So that deadline is properly updated.. NS_LOG_DEBUG("At " << Simulator::Now().As(Time::S) << " at BS uplink scheduler, processing bandwidth request from." diff --git a/src/wimax/model/dl-mac-messages.cc b/src/wimax/model/dl-mac-messages.cc index c59087327..22fb4b82f 100644 --- a/src/wimax/model/dl-mac-messages.cc +++ b/src/wimax/model/dl-mac-messages.cc @@ -407,11 +407,8 @@ Dcd::GetSerializedSize() const { uint32_t dlBurstProfilesSize = 0; - for (std::vector::const_iterator iter = m_dlBurstProfiles.begin(); - iter != m_dlBurstProfiles.end(); - ++iter) + for (const auto& burstProfile : m_dlBurstProfiles) { - OfdmDlBurstProfile burstProfile = *iter; dlBurstProfilesSize += burstProfile.GetSize(); } @@ -426,11 +423,8 @@ Dcd::Serialize(Buffer::Iterator start) const i.WriteU8(m_configurationChangeCount); i = m_channelEncodings.Write(i); - for (std::vector::const_iterator iter = m_dlBurstProfiles.begin(); - iter != m_dlBurstProfiles.end(); - ++iter) + for (const auto& burstProfile : m_dlBurstProfiles) { - OfdmDlBurstProfile burstProfile = *iter; i = burstProfile.Write(i); } } @@ -625,11 +619,8 @@ DlMap::GetSerializedSize() const { uint32_t dlMapElementsSize = 0; - for (std::list::const_iterator iter = m_dlMapElements.begin(); - iter != m_dlMapElements.end(); - ++iter) + for (const auto& dlMapIe : m_dlMapElements) { - OfdmDlMapIe dlMapIe = *iter; dlMapElementsSize += dlMapIe.GetSize(); } @@ -643,11 +634,8 @@ DlMap::Serialize(Buffer::Iterator start) const i.WriteU8(m_dcdCount); WriteTo(i, m_baseStationId); - for (std::list::const_iterator iter = m_dlMapElements.begin(); - iter != m_dlMapElements.end(); - ++iter) + for (const auto& dlMapIe : m_dlMapElements) { - OfdmDlMapIe dlMapIe = *iter; i = dlMapIe.Write(i); } } diff --git a/src/wimax/model/ofdm-downlink-frame-prefix.cc b/src/wimax/model/ofdm-downlink-frame-prefix.cc index 0ed617c2f..523329a0b 100644 --- a/src/wimax/model/ofdm-downlink-frame-prefix.cc +++ b/src/wimax/model/ofdm-downlink-frame-prefix.cc @@ -232,11 +232,8 @@ OfdmDownlinkFramePrefix::GetSerializedSize() const { int dlFramePrefixElementsSize = 0; - for (std::vector::const_iterator iter = m_dlFramePrefixElements.begin(); - iter != m_dlFramePrefixElements.end(); - iter++) + for (const auto& dlFramePrefixElement : m_dlFramePrefixElements) { - DlFramePrefixIe dlFramePrefixElement = *iter; dlFramePrefixElementsSize += dlFramePrefixElement.GetSize(); } @@ -251,11 +248,8 @@ OfdmDownlinkFramePrefix::Serialize(Buffer::Iterator start) const i.WriteU32(m_frameNumber); i.WriteU8(m_configurationChangeCount); - for (std::vector::const_iterator iter = m_dlFramePrefixElements.begin(); - iter != m_dlFramePrefixElements.end(); - iter++) + for (const auto& dlFramePrefixElement : m_dlFramePrefixElements) { - DlFramePrefixIe dlFramePrefixElement = *iter; i = dlFramePrefixElement.Write(i); } diff --git a/src/wimax/model/ul-mac-messages.cc b/src/wimax/model/ul-mac-messages.cc index a2dd3bd67..aee60e299 100644 --- a/src/wimax/model/ul-mac-messages.cc +++ b/src/wimax/model/ul-mac-messages.cc @@ -400,11 +400,8 @@ Ucd::GetSerializedSize() const { uint32_t ulBurstProfilesSize = 0; - for (std::vector::const_iterator iter = m_ulBurstProfiles.begin(); - iter != m_ulBurstProfiles.end(); - ++iter) + for (const auto& burstProfile : m_ulBurstProfiles) { - OfdmUlBurstProfile burstProfile = *iter; ulBurstProfilesSize += burstProfile.GetSize(); } @@ -422,11 +419,8 @@ Ucd::Serialize(Buffer::Iterator start) const i.WriteU8(m_requestBackoffEnd); i = m_channelEncodings.Write(i); - for (std::vector::const_iterator iter = m_ulBurstProfiles.begin(); - iter != m_ulBurstProfiles.end(); - ++iter) + for (const auto& burstProfile : m_ulBurstProfiles) { - OfdmUlBurstProfile burstProfile = *iter; i = burstProfile.Write(i); } } @@ -655,11 +649,9 @@ uint32_t UlMap::GetSerializedSize() const { uint32_t ulMapElementsSize = 0; - for (std::list::const_iterator iter = m_ulMapElements.begin(); - iter != m_ulMapElements.end(); - ++iter) + + for (const auto& ulMapIe : m_ulMapElements) { - OfdmUlMapIe ulMapIe = *iter; ulMapElementsSize += ulMapIe.GetSize(); } @@ -674,11 +666,8 @@ UlMap::Serialize(Buffer::Iterator start) const i.WriteU8(m_ucdCount); i.WriteU32(m_allocationStartTime); - for (std::list::const_iterator iter = m_ulMapElements.begin(); - iter != m_ulMapElements.end(); - ++iter) + for (const auto& ulMapIe : m_ulMapElements) { - OfdmUlMapIe ulMapIe = *iter; i = ulMapIe.Write(i); } }