From 1cc5fc3ebfacefe8326abb6c3367be6ddf524957 Mon Sep 17 00:00:00 2001 From: eladalon Date: Wed, 23 Aug 2017 04:15:18 -0700 Subject: [PATCH] Fix places that trigger no-unused-lambda-capture no-unused-lambda-capture was suppressed, but it's been decided as desireable to stop suppressing it. This CL fixes places in the code that trigger it. 1. Some unnecessary captures removed. 2. s/constexpr/const when capturing a float by value - this is good enough to stop the error. 3. Complete removal of the constexpr/const-modifier for int-types as a workaround. BUG=webrtc:7133 Review-Url: https://codereview.webrtc.org/3005433002 Cr-Commit-Position: refs/heads/master@{#19462} --- .../aec3/adaptive_fir_filter.cc | 2 +- .../aec3/adaptive_fir_filter_unittest.cc | 2 +- .../aec3/residual_echo_estimator.cc | 2 +- webrtc/pc/channel_unittest.cc | 12 ++++++---- webrtc/pc/rtcstatscollector_unittest.cc | 22 +++++++++---------- webrtc/pc/webrtcsession_unittest.cc | 2 +- webrtc/video/end_to_end_tests.cc | 10 ++++++--- .../video/overuse_frame_detector_unittest.cc | 2 +- 8 files changed, 31 insertions(+), 23 deletions(-) diff --git a/webrtc/modules/audio_processing/aec3/adaptive_fir_filter.cc b/webrtc/modules/audio_processing/aec3/adaptive_fir_filter.cc index 43cc901f00..09347e8324 100644 --- a/webrtc/modules/audio_processing/aec3/adaptive_fir_filter.cc +++ b/webrtc/modules/audio_processing/aec3/adaptive_fir_filter.cc @@ -507,7 +507,7 @@ void AdaptiveFirFilter::Constrain() { std::array h; fft_.Ifft(H_[partition_to_constrain_], &h); - constexpr float kScale = 1.0f / kFftLengthBy2; + const float kScale = 1.0f / kFftLengthBy2; std::for_each(h.begin(), h.begin() + kFftLengthBy2, [kScale](float& a) { a *= kScale; }); std::fill(h.begin() + kFftLengthBy2, h.end(), 0.f); diff --git a/webrtc/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc b/webrtc/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc index 32b20a4950..b9ab201991 100644 --- a/webrtc/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc +++ b/webrtc/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc @@ -337,7 +337,7 @@ TEST(AdaptiveFirFilter, FilterAndAdapt) { delay_buffer.Delay(x[0], y); RandomizeSampleVector(&random_generator, n); - constexpr float kNoiseScaling = 1.f / 100.f; + const float kNoiseScaling = 1.f / 100.f; std::transform( y.begin(), y.end(), n.begin(), y.begin(), [kNoiseScaling](float a, float b) { return a + b * kNoiseScaling; }); diff --git a/webrtc/modules/audio_processing/aec3/residual_echo_estimator.cc b/webrtc/modules/audio_processing/aec3/residual_echo_estimator.cc index 61208118c7..f3b310657d 100644 --- a/webrtc/modules/audio_processing/aec3/residual_echo_estimator.cc +++ b/webrtc/modules/audio_processing/aec3/residual_echo_estimator.cc @@ -32,7 +32,7 @@ void EchoGeneratingPower(const RenderBuffer& render_buffer, } // Apply soft noise gate of -78 dBFS. - constexpr float kNoiseGatePower = 27509.42f; + const float kNoiseGatePower = 27509.42f; std::for_each(X2->begin(), X2->end(), [kNoiseGatePower](float& a) { if (kNoiseGatePower > a) { a = std::max(0.f, a - 0.3f * (kNoiseGatePower - a)); diff --git a/webrtc/pc/channel_unittest.cc b/webrtc/pc/channel_unittest.cc index fa9d3da520..0eaffc426d 100644 --- a/webrtc/pc/channel_unittest.cc +++ b/webrtc/pc/channel_unittest.cc @@ -1205,9 +1205,13 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> { // Tests that when the transport channel signals a candidate pair change // event, the media channel will receive a call on the network route change. void TestNetworkRouteChanges() { - constexpr uint16_t kLocalNetId = 1; - constexpr uint16_t kRemoteNetId = 2; - constexpr int kLastPacketId = 100; + // These would have been declared as constexpr, but then some compilers + // require them to be captured in the lambda, and other compilers complain + // about no-ununused-lambda-capture. Keeping them as normal variables was + // the easiest work-around. + uint16_t kLocalNetId = 1; + uint16_t kRemoteNetId = 2; + int kLastPacketId = 100; CreateChannels(0, 0); @@ -1227,7 +1231,7 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> { EXPECT_FALSE(media_channel1->last_network_route().connected); media_channel1->set_num_network_route_changes(0); - network_thread_->Invoke(RTC_FROM_HERE, [this, media_channel1, + network_thread_->Invoke(RTC_FROM_HERE, [this, kLocalNetId, kRemoteNetId, kLastPacketId] { // The transport channel becomes connected. diff --git a/webrtc/pc/rtcstatscollector_unittest.cc b/webrtc/pc/rtcstatscollector_unittest.cc index f6591c0d66..4f3b35f55e 100644 --- a/webrtc/pc/rtcstatscollector_unittest.cc +++ b/webrtc/pc/rtcstatscollector_unittest.cc @@ -721,13 +721,13 @@ TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsSingle) { // Mock the session to return the local and remote certificates. EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( - [this](const ChannelNamePairs&) { + [](const ChannelNamePairs&) { std::unique_ptr stats(new SessionStats()); stats->transport_stats["transport"].transport_name = "transport"; return stats; })); EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly( - Invoke([this, &local_certinfo](const std::string& transport_name, + Invoke([&local_certinfo](const std::string& transport_name, rtc::scoped_refptr* certificate) { if (transport_name == "transport") { *certificate = local_certinfo->certificate; @@ -737,7 +737,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsSingle) { })); EXPECT_CALL(test_->session(), GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke( - [this, &remote_certinfo](const std::string& transport_name) { + [&remote_certinfo](const std::string& transport_name) { if (transport_name == "transport") return remote_certinfo->certificate->ssl_certificate().GetReference(); return static_cast(nullptr); @@ -892,14 +892,14 @@ TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsMultiple) { // Mock the session to return the local and remote certificates. EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( - [this](const ChannelNamePairs&) { + [](const ChannelNamePairs&) { std::unique_ptr stats(new SessionStats()); stats->transport_stats["audio"].transport_name = "audio"; stats->transport_stats["video"].transport_name = "video"; return stats; })); EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly( - Invoke([this, &audio_local_certinfo, &video_local_certinfo]( + Invoke([&audio_local_certinfo, &video_local_certinfo]( const std::string& transport_name, rtc::scoped_refptr* certificate) { if (transport_name == "audio") { @@ -914,7 +914,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsMultiple) { })); EXPECT_CALL(test_->session(), GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke( - [this, &audio_remote_certinfo, &video_remote_certinfo]( + [&audio_remote_certinfo, &video_remote_certinfo]( const std::string& transport_name) { if (transport_name == "audio") { return audio_remote_certinfo->certificate->ssl_certificate() @@ -952,13 +952,13 @@ TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsChain) { // Mock the session to return the local and remote certificates. EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( - [this](const ChannelNamePairs&) { + [](const ChannelNamePairs&) { std::unique_ptr stats(new SessionStats()); stats->transport_stats["transport"].transport_name = "transport"; return stats; })); EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly( - Invoke([this, &local_certinfo](const std::string& transport_name, + Invoke([&local_certinfo](const std::string& transport_name, rtc::scoped_refptr* certificate) { if (transport_name == "transport") { *certificate = local_certinfo->certificate; @@ -968,7 +968,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsChain) { })); EXPECT_CALL(test_->session(), GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke( - [this, &remote_certinfo](const std::string& transport_name) { + [&remote_certinfo](const std::string& transport_name) { if (transport_name == "transport") return remote_certinfo->certificate->ssl_certificate().GetReference(); return static_cast(nullptr); @@ -2278,7 +2278,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { CreateFakeCertificateAndInfoFromDers( std::vector({ "(remote) local", "(remote) chain" })); EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly( - Invoke([this, &local_certinfo](const std::string& transport_name, + Invoke([&local_certinfo](const std::string& transport_name, rtc::scoped_refptr* certificate) { if (transport_name == "transport") { *certificate = local_certinfo->certificate; @@ -2288,7 +2288,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { })); EXPECT_CALL(test_->session(), GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke( - [this, &remote_certinfo](const std::string& transport_name) { + [&remote_certinfo](const std::string& transport_name) { if (transport_name == "transport") return remote_certinfo->certificate->ssl_certificate().GetReference(); return static_cast(nullptr); diff --git a/webrtc/pc/webrtcsession_unittest.cc b/webrtc/pc/webrtcsession_unittest.cc index bb1c877a5c..6c9dcecbb9 100644 --- a/webrtc/pc/webrtcsession_unittest.cc +++ b/webrtc/pc/webrtcsession_unittest.cc @@ -3264,7 +3264,7 @@ TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) { // Checks if one of the transport channels contains a connection using a given // port. - auto connection_with_remote_port = [this, voice_channel](int port) { + auto connection_with_remote_port = [this](int port) { std::unique_ptr stats = session_->GetStats_s(); for (auto& kv : stats->transport_stats) { for (auto& chan_stat : kv.second.channel_stats) { diff --git a/webrtc/video/end_to_end_tests.cc b/webrtc/video/end_to_end_tests.cc index a4d7033603..f0cbf3e5c5 100644 --- a/webrtc/video/end_to_end_tests.cc +++ b/webrtc/video/end_to_end_tests.cc @@ -4278,9 +4278,13 @@ TEST_F(EndToEndTest, MAYBE_TestFlexfecRtpStatePreservation) { rtc::CriticalSection crit_; } observer; - constexpr int kFrameMaxWidth = 320; - constexpr int kFrameMaxHeight = 180; - constexpr int kFrameRate = 15; + // These would have been declared as constexpr, but then some compilers + // require them to be captured in the lambda, and other compilers complain + // about no-ununused-lambda-capture. Keeping them as normal variables was + // the easiest work-around. + int kFrameMaxWidth = 320; + int kFrameMaxHeight = 180; + int kFrameRate = 15; Call::Config config(event_log_.get()); diff --git a/webrtc/video/overuse_frame_detector_unittest.cc b/webrtc/video/overuse_frame_detector_unittest.cc index e52efcbacf..80faf657ee 100644 --- a/webrtc/video/overuse_frame_detector_unittest.cc +++ b/webrtc/video/overuse_frame_detector_unittest.cc @@ -357,7 +357,7 @@ TEST_F(OveruseFrameDetectorTest, RunOnTqNormalUsage) { event.Set(); })); - queue.PostTask([this, &event] { + queue.PostTask([this] { const int kDelayUs1 = 5 * rtc::kNumMicrosecsPerMillisec; const int kDelayUs2 = 6 * rtc::kNumMicrosecsPerMillisec; InsertAndSendFramesWithInterval(1300, kFrameIntervalUs, kWidth, kHeight,