Bug 306787

Summary: check-webkit-style: add checker for protect() in variable initialization
Product: WebKit Reporter: David Kilzer (:ddkilzer) <ddkilzer>
Component: Tools / TestsAssignee: David Kilzer (:ddkilzer) <ddkilzer>
Status: RESOLVED FIXED    
Severity: Normal CC: webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

David Kilzer (:ddkilzer)
Reported 2026-02-02 10:58:29 PST
The check-webkit-style tool should warn about using `protect()` free function when assigning to RefPtr/Ref variables, which violates SaferCPP guidelines. Bad patterns that should trigger warnings: ```cpp auto foo = protect(m_foo); RefPtr bar = protect(foo()); if (RefPtr client = protect(client())) ``` Good patterns that should NOT trigger warnings: ```cpp protect(foo)->doSomething(); // Method chaining - valid use someFunction(protect(foo)); // Function argument - valid use return protect(m_foo); // Return value - valid use ``` See also: <https://github.com/WebKit/WebKit/wiki/Safer-CPP-Guidelines#do-not-call-protect-free-function-to-initialize-local-variables>
Attachments
Radar WebKit Bug Importer
Comment 1 2026-02-02 10:58:36 PST
David Kilzer (:ddkilzer)
Comment 2 2026-02-02 11:18:25 PST
EWS
Comment 3 2026-02-04 05:26:10 PST
Committed 306771@main (3fa54a20c8ad): <https://commits.webkit.org/306771@main> Reviewed commits have been landed. Closing PR #57712 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.