Skip to content

fix: clear proc_results_ in Option::clear() to avoid stale processed values#1360

Merged
henryiii merged 2 commits into
mainfrom
fix/option-clear-proc-results
Jul 1, 2026
Merged

fix: clear proc_results_ in Option::clear() to avoid stale processed values#1360
henryiii merged 2 commits into
mainfrom
fix/option-clear-proc-results

Conversation

@henryiii

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Summary

  • Bug: Option::clear() reset results_ and current_option_state_ but not proc_results_. The fast path in results(T&) (include/CLI/Option.hpp ~line 726) returns proc_results_ whenever it is non-empty, so any as<T>() call after clear() returned the old processed value instead of the newly added one.
  • Scenario: Parse --x 2 --x 3 with MultiOptionPolicy::Sum (fills proc_results_ = {"5"}), then opt->clear(); opt->add_result("7"); opt->as<int>() returned 5 instead of 7.
  • Fix: Add proc_results_.clear(); inside Option::clear() (include/CLI/Option.hpp).
  • Test: Added SumOptClearResetsProc to tests/AppTest.cpp to reproduce the exact scenario and assert the post-clear value is correct.

Part of #1357

…values

Option::clear() was resetting results_ and current_option_state_ but not
proc_results_. The fast path in results(T&) uses proc_results_ whenever
it is non-empty, so a subsequent add_result()+as<T>() call after clear()
returned the old processed value instead of the new one.

Add proc_results_.clear() and a regression test covering the Sum policy
scenario described in issue #1357.

Assisted-by: ClaudeCode:claude-sonnet-4-6
Cast `opt->as<int>()` to void to satisfy [[nodiscard]] attribute
and fix clang-tidy/warnings-as-errors CI failures.

Assisted-by: ClaudeCode:claude-sonnet-4.6
@henryiii henryiii marked this pull request as ready for review June 14, 2026 00:22
@henryiii henryiii merged commit 0637736 into main Jul 1, 2026
73 checks passed
@henryiii henryiii deleted the fix/option-clear-proc-results branch July 1, 2026 20:14
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.

1 participant