Skip to content

Fix SFINAE group J: C++20/23 traits, iterator adaptors, pointer_traits, span and string_view - #87

Merged
jmgilbert2 merged 7 commits into
masterfrom
fix/group-j
Nov 7, 2026
Merged

jmgilbert2 merged 7 commits into
masterfrom
fix/group-j

Conversation

@jmgilbert2

@jmgilbert2 jmgilbert2 commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Fixes SFINAE audit group J (cases 40, 89, 90, 104, 106, 107, 280, 294, 306, 307) and the related gaps found by sweeping the same components against MSVC STL. One commit per component.

The sweep is 69 std-vs-EASTL cases (jcases.cpp in the probe harness; cl, clang-cl and clang-cl MS mode; C++17 and latest), covering the probed cases and their siblings. On master, 52 of them differ from std. With this PR, all 69 match std.

Type traits (2762431)

  • underlying_type<T> has no member type for a non-enumeration (it was a hard error).
  • New: is_nothrow_convertible, is_scoped_enum (C++23), unwrap_reference, unwrap_ref_decay, common_reference and basic_common_reference. common_reference follows the standard's steps with C++23's convertibility rule (P2655), and gives the same type as MSVC STL on 31 type combinations (references of every cv and value category, derived/base, conversions, three types, no common type).
  • is_constant_evaluated is declared in type_traits.h, where std declares it. numeric.h still provides it.

iterator_traits, reverse_iterator, move_iterator, move_sentinel (9307f4c)

  • iterator_traits<T*> only for object types (iterator_traits<void*> was a hard error), with a cv-unqualified value_type.
  • An iterator with no pointer member gets pointer = void, as in C++20.
  • Pointers get iterator_concept = contiguous_iterator_tag where that tag exists. With std iterator tags in C++17 there is none, so pointers have no iterator_concept there.
  • Both adaptors:
    • the converting constructor and assignment only participate if the base iterator converts;
    • every comparison only participates if its base comparison is valid;
    • C++20 gets operator<=>;
    • both have iterator_concept.
  • reverse_iterator:
    • operator- returns the base difference's type;
    • operator-> exists only for a pointer or a base with operator->, which it now calls.
  • Bug: move_iterator's converting assignment didn't compile at all. It read a protected member of another specialization; it now uses base().
  • move_sentinel is added.

pointer_traits (fd049b6)

  • No members when the element type can't be determined (LWG 3545). Before, element_type was the pointer type itself.
  • rebind<U> of a pointer class template without a rebind member is P<U, Args...>. Before, the member was required.
  • Bug: pointer_traits<void*> and pointer_traits of a void pointer template were hard errors (pointer_to(void&)). They now work, using a placeholder parameter type as MSVC does.

span (78592d0)

  • Explicit for a static extent, as in std: the constructors from a pointer and a size or an end, from a container, and from a span of dynamic extent. span<int> converted implicitly to span<int, 3>.
  • The array constructors take an array of any convertible element type, so span<int> no longer reports constructible from a const array<int, N>&. The container constructors leave every array and span to the dedicated constructors.
  • New: as_bytes and as_writable_bytes (with std::byte).
  • first<N>, last<N> and subspan<O, N> construct their results explicitly.

string, string_view (82ae71e, 5ea38b8)

  • basic_string(nullptr) and = nullptr are deleted, as in C++23. They were an argument error or a null dereference in CharStrlen.
  • basic_string_view(nullptr) is deleted too (5ea38b8). It used to give an empty view, an EASTL extension that TestStringView.inl tested as a "user-reported regression" (since 3.08.00). A null pointer isn't a string, so like C++23 it no longer compiles, and NULL or 0 are ambiguous. That test now checks the deletion, and that a null const T* variable still gives an empty view, as before. std reads through it, which is undefined behaviour. That check is kept on purpose; 38c7986 documents it at the constructor.
  • New: the C++20 iterator-pair constructor (for pointers, which are EASTL's contiguous iterators) and C++23's explicit range constructor. Like std, the range constructor doesn't take a basic_string_view, a type that converts to const T*, or a type with its own conversion to basic_string_view such as basic_string.

Behaviour changes to review:

  • span<int, 3> s = {p, 3}; and the implicit span<int> → span<int, 3> / vector<int>& → span<int, 3> conversions no longer compile (std rejects them too).
  • string_view(nullptr), string_view(NULL) and string_view(0) no longer compile.
  • iterator_traits<volatile T*>::value_type is T.
  • reverse_iterator::operator-> calls the base iterator's operator-> instead of taking &*.

Not covered: the C++20 iterator_traits synthesized from the C++17 iterator concepts, for types without member types. It needs the C++20 iterator concepts library (incrementable_traits, indirectly_readable_traits, ...), which EASTL doesn't have.

Tests: TestTypeTraits, TestIterator (including the move_iterator converting assignment and a move_sentinel loop), TestMemory, TestSpan, TestStringView. Each fails to compile on master.

The other SFINAE probes (cases, xadl, alg2, cont2, cases2) change only in group J'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 7 commits November 6, 2026 22:33
Like std:
- underlying_type<T> has no member type when T isn't an enumeration,
  instead of a hard error, so it can be used in SFINAE;
- is_nothrow_convertible (C++20) and is_scoped_enum (C++23) are added;
- unwrap_reference and unwrap_ref_decay (C++20) are added;
- common_reference and basic_common_reference (C++20) are added, with
  C++23's convertibility rule (P2655), and match MSVC STL on 31 type
  combinations;
- is_constant_evaluated is declared in type_traits.h, where std
  declares it, instead of numeric.h (which still provides it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
iterator_traits:
- only pointers to object types have traits (iterator_traits<void*> was
  a hard error), and the value type is cv-unqualified;
- an iterator with the other four member types but no pointer gets
  pointer = void;
- pointers get iterator_concept = contiguous_iterator_tag where that tag
  exists.

reverse_iterator and move_iterator:
- the converting constructor and assignment only participate if the base
  iterator converts (reverse_iterator<int*> from reverse_iterator<const
  int*> was reported constructible);
- every comparison only participates if the base comparison it makes is
  valid, and C++20 gets operator<=>;
- reverse_iterator's difference is the base difference's type, its
  operator-> exists only for a pointer or a base with operator->, which
  it calls, and both get iterator_concept;
- move_iterator's converting assignment compiles: it read a protected
  member of another specialization.

move_sentinel (C++20) is added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like std:
- pointer_traits<P> has no members when P has no element type (LWG
  3545); before, element_type was P itself;
- rebind<U> of a pointer class template without a rebind member is
  P<U, Args...>; it required the member;
- pointer_traits<void*> and pointer_traits of a void pointer template
  are usable: pointer_to took a void& parameter, a hard error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like std:
- the constructors from a pointer and a size or an end, from a container
  and from a span of dynamic extent are explicit when the extent is
  static (span<int> converted implicitly to span<int, 3>);
- the array constructors take an array of any element type that
  converts, so span<int> no longer accepts a const array, and the
  container constructors leave every array and span to them;
- as_bytes and as_writable_bytes are added.

first<N>, last<N> and subspan<O, N> now construct their result
explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like std (C++23), basic_string can't be constructed from or assigned a
nullptr: it was an argument error or a null dereference.
basic_string_view(nullptr) stays an empty view, an EASTL extension
TestStringView.inl tests.

basic_string_view gets the C++20 iterator-pair constructor, for
pointers, and C++23's explicit range constructor, which doesn't take a
basic_string_view, a type that converts to const T*, or one with its
own conversion to basic_string_view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
basic_string_view(nullptr) gave an empty view, an EASTL extension that
TestStringView.inl tested. Like std (C++23), it's now deleted, and NULL
or 0 are ambiguous: a null pointer isn't a string. A null const T*
variable still gives an empty view, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
basic_string_view(const T*) gives an empty view for a null pointer
instead of reading through it as std does. That stays, on purpose; the
comment says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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