Do not treat std::array as implicitly reflectable (#169)#234
Open
DuminAndrew wants to merge 1 commit into
Open
Do not treat std::array as implicitly reflectable (#169)#234DuminAndrew wants to merge 1 commit into
DuminAndrew wants to merge 1 commit into
Conversation
std::array is an aggregate, so is_implicitly_reflectable_v reported it as reflectable. However, std::array stores its elements in a single C array member, which Boost.PFR can not reflect correctly yet (boostorg#20): the field count and per-field access are wrong. Downstream users of is_reflectable therefore mis-handle std::array. Exclude std::array from the implicit reflection decision via a dedicated detail::is_stdarray trait, so is_implicitly_reflectable reports false for it and its cv-qualified variants. Other aggregates are unaffected. Closes boostorg#169.
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
boost::pfr::is_implicitly_reflectable_v<std::array<T, N>>evaluates totruebecause
std::arrayis an aggregate. Butstd::arraykeeps its elements in asingle C array data member, which Boost.PFR can not reflect correctly yet
(#20) — tuple size and per-field access are wrong. Since downstream adaptors
use
is_reflectable/is_implicitly_reflectableto decide whether to route atype through PFR, the trait reporting
truemakes them mis-handlestd::array.This is the explicit request in #169.
Change
detail::is_stdarraytrait.std::arrayfrom the implicit reflection branch indetail/possible_reflectable.hpp, both with and without__cpp_lib_is_aggregate.The change only affects the
is_implicitly_reflectabledecision; ordinaryaggregates are unaffected, and no public API is added or removed.
Tests
Extended
test/core/run/is_implicitly_reflectable.cppto assert thatstd::array(and its cv-qualified forms) is non-reflectable for both theboost_json_tagandboost_fusion_tagtags, while plain aggregates stayreflectable.
Verified locally with g++ 15.2 at
cxxstd=14/17/20; the existingis_reflectable,is_implicitly_reflectable, andtuple_sizerun-testscontinue to pass.
Closes #169.