[webkit-dev] Use of [[maybe_unused]]

Suzuki, Basuke Basuke.Suzuki at sony.com
Mon Jan 13 16:08:32 PST 2020

Hi WebKit-dev,

I'm asking about whether we can use C++ 17's new attribute [[maybe_unused]]. These are situations I cannot solve well with UNUSED_PARAM().

Case 1: The function parameter is only used in RELEASE_LOG macro which is empty in some platform

    m_workQueue->dispatch([this, host = host.isolatedCopy(), sessionID, callback = WTFMove(callback)] () mutable {
        RELEASE_LOG_IF_ALLOWED(sessionID, "query - Ran successfully. Result = %s", (foundHost ? "true" : "false"));

`sessionID` is used in RELEASE_LOG_IF_ALLOWED() and we have empty implementation of RELEASE_LOG() so that it's ended up with unused parameter warning of sessionID. We can add UNUSED_PARAM(sessionID) in this case, but [[maybe_unused]] is more correct choice to describe the code because sessionID is actually used.

I also tried to replace empty RELEASE_LOG macro with something to use every parameter marked used somehow, but the trial just failed.

Case 2: The member variable is just used by specific port

    bool m_isHTTPSUpgradeEnabled { false };

This member variable is only used in COCOA port. (https://github.com/WebKit/webkit/blob/master/Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp#L203)

We can add UNUSED_PARAM(isHTTPSUpgradeEnabled) in our platform code, but adding [[maybe_unused]] in the header file is straight forward.

Compiler support of this attribute seems okay for any WebKit build. I've done quick check on Godbolt. https://godbolt.org/z/w47XXn

Basuke Suzuki
SONY PlayStation

More information about the webkit-dev mailing list