We've migrated most instances of WARN_UNUSED_RESULT to [[nodiscard]]. However, there's an interesting question of what we should do for Objective-C/Objective-C++ code.
Somewhat surprisingly, it seems that C++ attributes work:
$ third_party/llvm-build/Release+Asserts/bin/clang -ObjC++ test.mm
test.mm:13:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
Though not in regular Objective-C:
$ third_party/llvm-build/Release+Asserts/bin/clang -ObjC test.mm
test.mm:2:12: error: expected ';' after method prototype
- (int)test [[nodiscard]];
It seems like we have a few Objective-C files in the tree:
$ git ls-files | grep "\.m$" | grep -v third_party
And [[nodiscard]] definitely will not work for those. Do the Objective-C experts have any opinions on how we should approach this? I can think of several approaches:
1. Add base/mac/warn_unused_result.h for use in Objective-C/Objective-C++ code and ban [[nodiscard]] for Objective-C interfaces.
2. Move all the .m files to .mm files and use [[nodiscard]] everywhere, even in Objective-C interfaces.
3. Kick the can down the road. Use [[nodiscard]] everywhere since no Objective-C files currently use WARN_UNUSED_RESULT and hope for the best.
I'm assuming we'll end up with some variation of #1 or #2, but would love to hear feedback.