Skip to content

Conversation

@copybara-service
Copy link

Add [[nodiscard]] to const message field accessors.

This covers logically constant APIs (similar to the guidance in
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3122r1.html) where
ignoring the return value likely indicates an omission on the part of the
caller or a call that can be cleaned up.

For example:
my_message.mutable_child().grandchild()

Creates a child instance but grandchild() is a no-op. mutable_grandchild() may
have been intended.

This covers logically constant APIs (similar to the guidance in
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3122r1.html) where
ignoring the return value likely indicates an omission on the part of the
caller or a call that can be cleaned up.

For example:
  my_message.mutable_child().grandchild()

Creates a child instance but grandchild() is a no-op.  mutable_grandchild() may
have been intended.

PiperOrigin-RevId: 788578034
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants