Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Issue 2672823002: Don't capture variables explicitly in lambda expression. (Closed)

Created:
3 years, 10 months ago by ehmaldonado_webrtc
Modified:
3 years, 10 months ago
Target Ref:
refs/heads/master
Project:
webrtc
Visibility:
Public.

Description

Don't capture variables explicitly in lambda expression. As it is, the test fails to compile on some downstream compilers with the following error: webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc:316:25: error: lambda capture 'kPayloadLength' is not required to be captured for this use [-Werror,-Wunused-lambda-capture] .WillOnce(Invoke([kPayloadLength, kFirstSequenceNumber, kFirstTimestamp, ^ webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc:316:41: error: lambda capture 'kFirstSequenceNumber' is not required to be captured for this use [-Werror,-Wunused-lambda-capture] .WillOnce(Invoke([kPayloadLength, kFirstSequenceNumber, kFirstTimestamp, ^ webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc:316:63: error: lambda capture 'kFirstTimestamp' is not required to be captured for this use [-Werror,-Wunused-lambda-capture] .WillOnce(Invoke([kPayloadLength, kFirstSequenceNumber, kFirstTimestamp, ^ webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc:317:25: error: lambda capture 'kFirstReceiveTime' is not required to be captured for this use [-Werror,-Wunused-lambda-capture] kFirstReceiveTime](const SdpAudioFormat& format, BUG=webrtc:7107 Review-Url: https://codereview.webrtc.org/2672823002 Cr-Commit-Position: refs/heads/master@{#16422} Committed: https://chromium.googlesource.com/external/webrtc/+/b55bd5fef07f5f07438b3cafa340adb9072a619a

Patch Set 1 #

Total comments: 2

Patch Set 2 : Capture by reference, not by value. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+2 lines, -3 lines) Patch
M webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc View 1 1 chunk +2 lines, -3 lines 0 comments Download

Messages

Total messages: 17 (8 generated)
ehmaldonado_webrtc
3 years, 10 months ago (2017-02-02 17:45:02 UTC) #6
kwiberg-webrtc
https://codereview.webrtc.org/2672823002/diff/20001/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc File webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc (right): https://codereview.webrtc.org/2672823002/diff/20001/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc#newcode317 webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc:317: std::unique_ptr<AudioDecoder>* dec) { Uh? I clearly see those constants ...
3 years, 10 months ago (2017-02-02 18:24:59 UTC) #7
ehmaldonado_webrtc
PTAL > (Yes, that means the lambda must not be called after the end of ...
3 years, 10 months ago (2017-02-02 18:47:03 UTC) #8
kwiberg-webrtc
On 2017/02/02 18:47:03, ehmaldonado_webrtc wrote: > PTAL lgtm > > (Yes, that means the lambda ...
3 years, 10 months ago (2017-02-02 19:01:38 UTC) #9
ehmaldonado_webrtc
> A lambda that captures any local variable by reference will be the proud owner ...
3 years, 10 months ago (2017-02-02 19:03:16 UTC) #10
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/2672823002/40001
3 years, 10 months ago (2017-02-02 19:03:32 UTC) #12
commit-bot: I haz the power
Committed patchset #2 (id:40001) as https://chromium.googlesource.com/external/webrtc/+/b55bd5fef07f5f07438b3cafa340adb9072a619a
3 years, 10 months ago (2017-02-02 19:51:29 UTC) #15
hlundin-webrtc
lgtm
3 years, 10 months ago (2017-02-06 09:16:01 UTC) #16
ossu
3 years, 10 months ago (2017-02-06 14:20:51 UTC) #17
Message was sent while issue was closed.
https://codereview.webrtc.org/2672823002/diff/20001/webrtc/modules/audio_codi...
File webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc (right):

https://codereview.webrtc.org/2672823002/diff/20001/webrtc/modules/audio_codi...
webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc:317:
std::unique_ptr<AudioDecoder>* dec) {
On 2017/02/02 18:24:59, kwiberg-webrtc wrote:
> Uh? I clearly see those constants being used a bit further down in the lambda
> body... whatever compiler you're using must be confused.
> 
> However. If you must make a default capture, it's probably better to capture
by
> reference. Otherwise, it's very hard to see exactly what sort of copy
> constructors end up being called.
> 
> (Yes, that means the lambda must not be called after the end of the block in
> which it was created, but that is the case here. If it weren't the case, I
would
> have objected to default capturing, by reference OR by value.)

If I were to guess as to why this happens, it's the compiler replacing constants
with literal values in the lambda body and only afterwards checking for
unnecessary captures. Very strange. Sounds like a compiler bug. Which compiler
does this? GCC? MSVC?

Powered by Google App Engine
This is Rietveld 408576698