google / google/emboss

Add [[nodiscard]] annotations to generated C++ code

Open
#242 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
92
Forks
30
PR merge metrics
No merged PRs in 30d

Description

## 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:
1. Require C++17 minimum and add `[[nodiscard]]` unconditionally
2. Use a macro that expands to `[[nodiscard]]` on C++17+ and nothing on C++14
3. 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)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.