[PATCH] D156261: [NFC] Cast unchecked return values to void.

Sindhu Chittireddy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 27 09:23:20 PDT 2023


schittir added a comment.

In D156261#4535220 <https://reviews.llvm.org/D156261#4535220>, @aaron.ballman wrote:

> I think the cast to void is unneeded in these cases. We typically add a cast to void when the function exists to compute a result but also has side effects. e.g., you typically call `malloc()` because you want the returned pointer, but if for some reason you don't want the pointer but still want the side effect of the memory allocation, you'd cast the result of the call to `void`. In this case, the `Traverse` functions exist mostly to perform side effects and the return value is only used to indicate "should we keep going?". It's reasonable to ignore the return value in this case if you don't intend to stop the traversal (and in this particular case, nothing will return `false` from the traversal and so there's really no need to check the return values here).

I see. Thank you for the explanation. I had mixed thoughts about whether casting to void is considered a best practice in general, in addition to the use of [[nodiscard]] wherever applicable. 
This seemed like a harmless change. I don't have strong opinions here, so I will go ahead and abandon these changes unless any one else disagrees.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156261/new/

https://reviews.llvm.org/D156261



More information about the cfe-commits mailing list