[DataBinder] Avoid std::span/iter_move ambiguity on MSVC STL#510
Merged
Merged
Conversation
SqlDynamicBinary exposes its byte payload as std::span<value_type const>
(constructor parameter, Bytes(), and the deprecated ToStringView()). On
Microsoft's STL, instantiating std::span<uint8_t const> realizes its
std::reverse_iterator specialization, which declares the legacy
std::iter_move hidden friend. Once that overload is visible in a translation
unit, the unqualified iter_move call inside std::ranges::enumerate_view's
iterator becomes ambiguous between it and the std::ranges::iter_move CPO,
so any translation unit that both instantiates SqlDynamicBinary and uses
std::views::enumerate fails with:
error C2872: 'iter_move': ambiguous symbol
It reproduces with cl.exe under /O2 (force-inlining realizes the span
iterator machinery); clang-cl and libstdc++/libc++ are unaffected, and it is
a known MSVC STL interaction rather than a defect in this library.
Introduce a ByteView alias and select the view type per standard library:
std::basic_string_view<value_type> on MSVC's STL (its iterators do not pull
the conflicting iter_move into scope), std::span<value_type const>
elsewhere. std::span is retained off-MSVC because std::basic_string_view<uint8_t>
is ill-formed there (no std::char_traits specialization for unsigned char),
which is the reason the span form was adopted in the first place.
Signed-off-by: Christian Parpart <c.parpart@lastrada.net>
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.
Problem
SqlDynamicBinaryexposes its byte payload asstd::span<value_type const>(the constructor parameter,Bytes(), and the deprecatedToStringView()).On Microsoft's STL, instantiating
std::span<uint8_t const>realizes itsstd::reverse_iteratorspecialization, which declares the legacystd::iter_movehidden friend. Once that overload is visible in a translation unit, the unqualifiediter_movecall insidestd::ranges::enumerate_view's iterator becomes ambiguous between it and thestd::ranges::iter_moveCPO. Any translation unit that both instantiatesSqlDynamicBinaryand usesstd::views::enumeratethen fails to compile:It reproduces with
cl.exeunder/O2(force-inlining realizes the span iterator machinery).clang-cl, libstdc++ and libc++ are unaffected — it is a known MSVC STL interaction, not a defect in this library.Fix
Introduce a
ByteViewalias and select the view type per standard library:std::basic_string_view<value_type>on MSVC's STL (_MSVC_STL_VERSION) — its iterators do not pull the conflictingiter_moveinto scope;std::span<value_type const>everywhere else.std::spanis retained off-MSVC becausestd::basic_string_view<uint8_t>is ill-formed there (nostd::char_traitsspecialization forunsigned char), which is why the span form was adopted originally.No public API changes beyond the view type alias;
Bytes()/ToStringView()keep their contract.