Summary
Consider adding [[nodiscard]] annotations to generated C++ code for methods like Ok(), Read(), TryToWrite(), etc. to help catch bugs where return values are accidentally ignored.
Background
This was originally part of PR #235 (optimization for conditional fields), but was requested to be split out for separate discussion since [[nodiscard]] is a C++17 feature and there may need to be a broader discussion about C++14 vs C++17 support.
Considerations
[[nodiscard]] was introduced in C++17
- Current Emboss may support C++14 users
- Options to consider:
- Require C++17 minimum and add
[[nodiscard]] unconditionally
- Use a macro that expands to
[[nodiscard]] on C++17+ and nothing on C++14
- Keep C++14 compatibility and don't add
[[nodiscard]]
Affected methods
Key methods that would benefit from [[nodiscard]]:
Ok() - return value indicates validity
Read() / UncheckedRead() - return values are the point of the call
TryToWrite() / TryToCopyFrom() - return value indicates success
IsComplete() - return value indicates completeness
CouldWriteValue() - return value indicates writability
cc @EricRahm (requested this be discussed separately)
Summary
Consider adding
[[nodiscard]]annotations to generated C++ code for methods likeOk(),Read(),TryToWrite(), etc. to help catch bugs where return values are accidentally ignored.Background
This was originally part of PR #235 (optimization for conditional fields), but was requested to be split out for separate discussion since
[[nodiscard]]is a C++17 feature and there may need to be a broader discussion about C++14 vs C++17 support.Considerations
[[nodiscard]]was introduced in C++17[[nodiscard]]unconditionally[[nodiscard]]on C++17+ and nothing on C++14[[nodiscard]]Affected methods
Key methods that would benefit from
[[nodiscard]]:Ok()- return value indicates validityRead()/UncheckedRead()- return values are the point of the callTryToWrite()/TryToCopyFrom()- return value indicates successIsComplete()- return value indicates completenessCouldWriteValue()- return value indicates writabilitycc @EricRahm (requested this be discussed separately)