fix: clear proc_results_ in Option::clear() to avoid stale processed values#1360
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Summary
Option::clear()resetresults_andcurrent_option_state_but notproc_results_. The fast path inresults(T&)(include/CLI/Option.hpp~line 726) returnsproc_results_whenever it is non-empty, so anyas<T>()call afterclear()returned the old processed value instead of the newly added one.--x 2 --x 3withMultiOptionPolicy::Sum(fillsproc_results_ = {"5"}), thenopt->clear(); opt->add_result("7"); opt->as<int>()returned5instead of7.proc_results_.clear();insideOption::clear()(include/CLI/Option.hpp).SumOptClearResetsProctotests/AppTest.cppto reproduce the exact scenario and assert the post-clear value is correct.Part of #1357