This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Cast unchecked return values to void.
AbandonedPublic

Authored by schittir on Jul 25 2023, 2:12 PM.

Details

Diff Detail

Event Timeline

schittir created this revision.Jul 25 2023, 2:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 2:12 PM
schittir requested review of this revision.Jul 25 2023, 2:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 2:12 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

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 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.

schittir abandoned this revision.Jul 27 2023, 9:39 AM