Skip to content

Constrain any's converting and in-place constructors and assignment, like std - #84

Merged
jmgilbert2 merged 2 commits into
masterfrom
fix/any-copyable-constraint
Nov 7, 2026
Merged

jmgilbert2 merged 2 commits into
masterfrom
fix/any-copyable-constraint

Conversation

@jmgilbert2

@jmgilbert2 jmgilbert2 commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Fixes SFINAE audit group I (cases 315, 317) and the related in-place constructor bugs found next to it. any's converting constructor and assignment only static_asserted that the value type is copy constructible, so is_constructible<any, NonCopyable> and is_assignable<any&, NonCopyable> were true and the body failed. Each item below differed from MSVC STL, which follows the standard.

Like std ([any.cons], [any.assign]):

  • the converting constructor and assignment participate only if the decayed value type is copy constructible and isn't any or an in_place_type_t. The in_place_type_t exclusion is part of the same constraint: before, any a = in_place_type<int>; stored the tag object instead of failing to compile. The assignment now also excludes any itself, so a = b with a non-const any lvalue goes straight to copy assignment, with the same result;
  • the in-place constructors participate only if the decayed type is copy constructible and constructible from the arguments. Before, any(in_place_type<NonCopyable>) reported constructible.

Also fixed: any(in_place_type<T>, {list}, args...) didn't compile at all. The initializer_list constructor's constraint was a defaulted parameter after the Args&&... pack, and a function parameter pack that isn't last is never deduced, so any argument after the list was rejected. The constraint is now a template parameter.

Tests (TestAny): the traits above, in_place_type_t isn't convertible to any, in-place construction still works, assignment from a non-const any lvalue still copies, and in-place construction from a list followed by another argument. On master the trait asserts and the list-plus-argument construction fail to compile.

The SFINAE probes change only in group I's cases.

Verification: VS 2026 cl 14.51 and clang-cl 22, C++17 and latest, Debug and Release: all 8 EASTL suites pass, no new warnings compared with master.

🤖 Generated with Claude Code

jmgilbert2 and others added 2 commits November 6, 2026 18:30
Both only static_asserted that the value type is copy constructible,
so traits reported any as constructible and assignable from a
non-copyable type. They now don't participate for a non-copyable value
type, any itself or an in_place_type_t.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They now participate only for a decayed type that is copy constructible
and constructible from the arguments; before, the first only
static_asserted and neither checked copyability. The constraint of the
initializer_list one moves from a trailing parameter into the template
parameters: after the Args pack, that parameter kept the pack from
being deduced, so any(in_place_type<T>, {list}, args...) didn't
compile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmgilbert2 jmgilbert2 changed the title Constrain any's converting constructor and assignment, like std Constrain any's converting and in-place constructors and assignment, like std Nov 7, 2026
@jmgilbert2
jmgilbert2 merged commit cd79f8c into master Nov 7, 2026
28 checks passed
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