Summary: | Define _LIBCPP_ENABLE_NODISCARD when building WebKit | ||
---|---|---|---|
Product: | WebKit | Reporter: | David Kilzer (:ddkilzer) <ddkilzer> |
Component: | WebKit Misc. | Assignee: | Nobody <webkit-unassigned> |
Status: | NEW --- | ||
Severity: | Normal | CC: | joepeck, webkit-bug-importer |
Priority: | P2 | Keywords: | InRadar |
Version: | Other | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
Description
David Kilzer (:ddkilzer)
2020-12-17 19:22:02 PST
Nice! (In reply to David Kilzer (:ddkilzer) from comment #0) > Define _LIBCPP_ENABLE_NODISCARD when building WebKit. > > This will catch errors where a developer means to declare a variable (like a > resource acquisition is initialization (RAII) object), but forgets to give > it a variable name: > > SpmeRAIIObject { }; To be clear the `_LIBCPP_ENABLE_NODISCARD` only adds the `[[nodiscard]]` annotation to more of the `std` Standard Library Functions than already have it since C++17. --- If WebKit has its own classes where this is important (Lock Guards / Mutex Holders, Allocation / Copy / Ownership passing methods) then they should be annotated with `[[nodiscard]]` in order to get such warnings. Currently I see no `[[nodiscard]]` use in WebKit, but there is `WARN_UNUSED_RETURN` which is probably pretty similar. Things like: * RAII constructors - WTF::Locker for example * Ownership Passing methods that may leak if the result is not used - WTF::MallocPtr::leakPtr for example * Allocation methods that may leak if the result is not used - WTF::fastMalloc for example |