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.mmtest.mm:13:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
[self test];
^
Though not in regular Objective-C:
$ third_party/llvm-build/Release+Asserts/bin/clang -ObjC
test.mmtest.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
components/cronet/ios/cronet_consumer/cronet_consumer_view_controller.m
ios/chrome/browser/ui/material_components/chrome_app_bar_view_controller.m
ios/web_view/shell/shell_app_delegate.m
ios/web_view/shell/shell_auth_service_fake.m
ios/web_view/shell/shell_autofill_delegate.m
ios/web_view/shell/shell_exe_main.m
ios/web_view/shell/shell_risk_data_loader_fake.m
ios/web_view/shell/shell_translation_delegate.m
ios/web_view/shell/shell_trusted_vault_provider_fake.m
ios/web_view/shell/shell_view_controller.m
remoting/ios/mdc/MDCActionImageView.m
tools/mac/icons/makeicns2.m
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.
Daniel