Add generic value constructor to std/type/any#1214
Merged
Conversation
When an explicitly declared (non-generic) function and a generic substitution match a call equally well, overload resolution reported an ambiguity. Mirror C++ semantics and prefer the non-template, applied as a secondary tie-break after qualifier specificity. A losing generic substitution that was only inserted for this match is de-registered again, so the IR generator never emits a manifestation that was never type-checked. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Allow constructing an Any directly from a value, e.g. Any(42), in addition to the any() factory and set(). Extend the any-smoke and any-nontrivial tests to cover the new constructor on the inline, heap and non-trivial (copy-ctor/dtor tracked) paths. This relies on overload resolution preferring the dedicated copy constructor over the generic value constructor when copying an Any. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Base automatically changed from
fix/prefer-explicit-overload-over-generic
to
main
June 15, 2026 20:48
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.
What changed
Any.ctor<T>(const T& value)tostd/type/any, so anAnycan be constructed directly from a value (e.g.Any(42)), alongside the existingany()factory andset().any-smoketest to cover the value constructor on the inline (Any(42)) and heap (Any(small)) paths.any-nontrivialtest to cover the value constructor on a non-trivial payload, so the lifetime counters verify it deep-copies via the copy ctor and is destroyed correctly.Why
The value constructor is a natural, convenient way to box a value and matches
std::any's usage. Constructing from anotherAnymust still pick the dedicated copy constructor rather than the generic value constructor.How it was validated
cmake --build cmake-build-debug --target spice spicetest— builds cleancmake-build-debug/test/spicetest --gtest_filter='StdTests.type_any*'—type_anySmokeandtype_anyNontrivialpassFollow-up / known limitations
Anyis ambiguous between the copy ctor andAny.ctor<Any>. Base this PR's merge on Prefer explicitly declared overloads over generic substitutions #1213; once it lands, this branch should be retargeted/rebased ontomain.