Closed Bug 1775161 (Wdeprecated-this-capture) Opened 3 years ago Closed 1 month ago

Fix and re-enable C++20 -Wdeprecated-this-capture warnings

Categories

(Firefox Build System :: General, task, P3)

task

Tracking

(firefox149 fixed)

RESOLVED FIXED
149 Branch
Tracking Status
firefox149 --- fixed

People

(Reporter: cpeterson, Assigned: cpeterson)

References

Details

Attachments

(11 files)

7.15 KB, text/plain
Details
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

The implicit capture of *this when the capture default is = is deprecated in C++20:

https://en.cppreference.com/w/cpp/language/lambda#Lambda_capture

See the attached log file for the 48 -Wdeprecated-this-capture warnings currently reported in mozilla-central.

However, due to inconsistencies in how clang and gcc handle explicit this captures in -std=c++17 mode, we can't fix these warnings (without ugly #ifdefs) to make this code compatible with both clang and gcc until after we build as -std=c++20 by default (bug 1768116).

class C {
  void memberFunction() {}

  void testCapture() {
    [=]() { memberFunction(); }();
    // Implicit capture of *this is OK in clang and gcc -std=c++17.
    // -Wdeprecated-this-capture warning in clang -std=c++20.
    // -Wdeprecated warning in gcc -std=c++20.

    [=, this]() { memberFunction(); }();
    // Explicit capture of *this is OK in clang and gcc -std=c++20.
    // -Wc++20-extensions warning in clang -std=c++17.
    // Error in gcc -std=c++17 with no way to suppress it.
  }
};
Alias: Wdeprecated-this-capture
Keywords: meta
Summary: Fix and re-enable C++20 -Wdeprecated-this-capture warnings → [meta] Fix and re-enable C++20 -Wdeprecated-this-capture warnings

These -Wdeprecated-this-capture warnings only reported when compiled with -std=c++20. In the meantime, these warnings were downgraded from errors to warnings in bug 1781001 so fixing these warnings doesn't need to block updating to C++20.

See Also: → 1781001
See Also: → 1880776
Depends on: 1887580
Depends on: 1991366
Assignee: nobody → cpeterson
Keywords: meta
See Also: 1880776
Summary: [meta] Fix and re-enable C++20 -Wdeprecated-this-capture warnings → Fix and re-enable C++20 -Wdeprecated-this-capture warnings

build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp Line 636: implicit capture of 'this' with a capture default of '=' is deprecated
build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp Line 639: implicit capture of 'this' with a capture default of '=' is deprecated
build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp Line 660: implicit capture of 'this' with a capture default of '=' is deprecated
build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp Line 663: implicit capture of 'this' with a capture default of '=' is deprecated

dom/clients/manager/ClientHandleOpParent.cpp:89:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated

dom/media/ChannelMediaDecoder.cpp:406:17 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/MediaCache.cpp:1978:9 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated

dom/media/webrtc/jsapi/MediaTransportHandler.cpp:1034:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:1050:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:1283:9 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:561:11 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:586:15 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:635:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:765:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:811:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:897:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:915:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:946:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandler.cpp:993:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:121:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:132:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:143:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:156:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:185:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:227:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:240:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:260:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:279:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:296:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:308:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:334:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:346:13 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
dom/media/webrtc/jsapi/MediaTransportHandlerIPC.cpp:93:14 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated

toolkit/components/extensions/webrequest/StreamFilterParent.cpp:338:7 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
toolkit/components/extensions/webrequest/StreamFilterParent.cpp:361:7 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
toolkit/components/extensions/webrequest/StreamFilterParent.cpp:420:5 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
toolkit/components/extensions/webrequest/StreamFilterParent.cpp:426:7 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
toolkit/components/extensions/webrequest/StreamFilterParent.cpp:615:11 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
toolkit/components/extensions/webrequest/StreamFilterParent.cpp:633:11 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
toolkit/components/extensions/webrequest/StreamFilterParent.cpp:699:7 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated

gfx/thebes/gfxPlatformFontList.cpp:1707:20 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
gfx/thebes/gfxPlatformFontList.cpp:1942:40 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated

image/decoders/nsBMPDecoder.cpp:435:20 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
image/decoders/nsGIFDecoder2.cpp:454:20 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
image/decoders/nsICODecoder.cpp:644:20 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
image/decoders/nsIconDecoder.cpp:38:34 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
image/decoders/nsJPEGDecoder.cpp:194:34 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
image/decoders/nsJXLDecoder.cpp:79:34 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
image/decoders/nsPNGDecoder.cpp:362:34 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated

ipc/ipdl/test/gtest/TestAsyncReturns.cpp:64:9: warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture]

ipc/ipdl/test/gtest/TestAsyncReturns.cpp:72:9: warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture]

ipc/ipdl/test/gtest/TestHangs.cpp:134:1: warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture]

layout/forms/HTMLSelectEventListener.cpp:739:23 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
layout/generic/nsFlexContainerFrame.cpp:3796:18 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
layout/generic/nsFlexContainerFrame.cpp:3802:18 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated
layout/style/FontFaceImpl.cpp:466:5 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated

netwerk/ipc/DocumentLoadListener.cpp:975:15: error: implicit capture of 'this' with a capture default of '=' is deprecated [-Werror,-Wdeprecated-this-capture]

netwerk/protocol/http/nsHttpConnectionMgr.cpp:3011:9 [-Wdeprecated-this-capture] implicit capture of 'this' with a capture default of '=' is deprecated

widget/android/GeckoEditableSupport.cpp:653:21: error: implicit capture of 'this' with a capture default of '=' is deprecated [-Werror,-Wdeprecated-this-capture]
widget/android/GeckoEditableSupport.cpp:748:7: error: implicit capture of 'this' with a capture default of '=' is deprecated [-Werror,-Wdeprecated-this-capture]

And re-enable gcc's -Wdeprecated warnings, which were only disabled
because gcc didn't have a more precise flag to disable its warnings
about C++20 deprecated this captures.

Attachment #9541824 - Attachment description: Bug 1775161 - Fix -Wdeprecated-this-capture warnings in clang-plugin tests. r?#static-analysis-reviewers → Bug 1775161 - Fix -Wdeprecated-this-capture warnings in clang-plugin tests. r?nika
Attachment #9541824 - Attachment description: Bug 1775161 - Fix -Wdeprecated-this-capture warnings in clang-plugin tests. r?nika → Bug 1775161 - Fix -Wdeprecated-this-capture warnings in clang-plugin tests. r?#static-analysis-reviewers
Attachment #9541830 - Attachment description: Bug 1775161 - Fix -Wdeprecated-this-capture warnings in layout/forms. r?#layout-reviewers → Bug 1775161 - Fix -Wdeprecated-this-capture warnings in layout. r?#layout-reviewers
Pushed by cpeterson@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/4bfa5608a199 https://hg.mozilla.org/integration/autoland/rev/60c0db17b1a8 Fix -Wdeprecated-this-capture warnings in clang-plugin tests. r=nika https://github.com/mozilla-firefox/firefox/commit/39db7a135e18 https://hg.mozilla.org/integration/autoland/rev/2616ebcc10bb Fix -Wdeprecated-this-capture warnings in dom. r=dom-core,webrtc-reviewers,smaug,bwc,padenot https://github.com/mozilla-firefox/firefox/commit/8422d11245b3 https://hg.mozilla.org/integration/autoland/rev/6792c2db86a0 Fix -Wdeprecated-this-capture warnings in extensions/webrequest. r=extension-reviewers,robwu https://github.com/mozilla-firefox/firefox/commit/6c613d23c0ce https://hg.mozilla.org/integration/autoland/rev/a906e032683a Fix -Wdeprecated-this-capture warnings in gfx/thebes. r=gfx-reviewers,lsalzman https://github.com/mozilla-firefox/firefox/commit/d4665c788bc6 https://hg.mozilla.org/integration/autoland/rev/74b9a73893af Fix -Wdeprecated-this-capture warnings in image/decoders. r=tnikkel https://github.com/mozilla-firefox/firefox/commit/eeb6297d6cf7 https://hg.mozilla.org/integration/autoland/rev/e3ac82aac61c Fix -Wdeprecated-this-capture warnings in ipc/ipdl tests. r=ipc-reviewers,mccr8,nika https://github.com/mozilla-firefox/firefox/commit/dcfa9d3b1cbb https://hg.mozilla.org/integration/autoland/rev/04f668b3d2e0 Fix -Wdeprecated-this-capture warnings in layout. r=layout-reviewers,TYLin https://github.com/mozilla-firefox/firefox/commit/5d2fbd15631e https://hg.mozilla.org/integration/autoland/rev/66fc6fd04c98 Fix -Wdeprecated-this-capture warnings in netwerk. r=necko-reviewers,valentin https://github.com/mozilla-firefox/firefox/commit/234bbfb8040d https://hg.mozilla.org/integration/autoland/rev/2105d99307d1 Fix -Wdeprecated-this-capture warnings in widget/android. r=geckoview-reviewers,ohall https://github.com/mozilla-firefox/firefox/commit/787c6031b6e3 https://hg.mozilla.org/integration/autoland/rev/91ec7dfaaecc Re-enable -Wdeprecated-this-capture warnings. r=firefox-build-system-reviewers,ahochheiden
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: