fix(caster): deep-copy library value types ahead of scalar/string dispatch#1
Merged
Merged
Conversation
…patch
default_caster<yyjson::value> fell into the scalar string branch because
constructible_from<value, string_view> spuriously evaluated to true on both
MSVC and clang (constructors inherited via `using base::base`), throwing
"is not constructible from JSON string" for object/array input. This broke
DTOs that reflect a yyjson::value field under default_caster (e.g. DAS
MaaExecutionPlanDto::tasks[].pipeline_override) on MSVC, and direct
cast<yyjson::value> on every compiler.
- default_caster: add a deep-copy branch for library value-owning types
(default_initializable<T> && base_of_value<T> && requires{T(json)}) ranked
AHEAD of the scalar/string branches; returns T(json), which uses the
existing implicit converting ctor (doc_.copy_value) to clone the subtree
into a fresh self-owned value. Excludes non-owning _ref views.
- Tighten the three string-branch SFINAEs (4406/4412/4418) with
`&& !base_of_value<T>` as belt-and-suspenders.
- test_value_cast.cpp: regression covering direct cast<value>(object/number),
aggregate DTO with value field, and that string cast is unaffected.
Verified: DAS DasMaaPiRuntime 20/20 on MSVC (was 13 fail), DAS full
DasMaaPiTest 66 pass/0 fail on mingw; lib ctest 63/63 on clang (mingw),
including test.cpp 1000+ static_asserts compiling clean.
修复(转换器): 库 value 类型在 scalar/字符串派发之前深拷贝
constructible_from<value,string_view> 因继承构造函数在 MSVC/clang 上误报为
true,value 误入字符串分支对 object 输入抛 "not constructible from JSON string",
导致带 yyjson::value 字段的 DTO 在 default_caster 反射下于 MSVC 失败。
GLM-5 代表 Dusk 创建了这个提交
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
default_caster<yyjson::value>fell into the scalar string branch becausestd::constructible_from<yyjson::value, std::string_view>spuriously evaluates totrue(on both MSVC and clang — caused by constructors inherited throughusing base::base), throwing"is not constructible from JSON string"for object/array input. This breaks any DTO that reflects ayyjson::valuefield underdefault_caster(downstream symptom: DASMaaExecutionPlanDto::tasks[].pipeline_overrideon MSVC).Fix
if constexprindefault_caster::from_json): for the library's own value-owning types,return T(json)— uses the existing implicit converting ctor (doc_.copy_value) to clone the subtree into a fresh self-owned value (value-semantic, likereader::value).default_initializable<T>excludes non-owning_refviews.&& !writer::detail::base_of_value<T>— belt-and-suspenders.test/test_value_cast.cpp.Verification
ctest63/63, 0 fail. Includestest.cpp(1000+static_asserts compiling clean),test_msvc_regression,test_aggregate_fallback(string-cast guard),test_value_cast.DasMaaPiRuntime20/20 on MSVC (was 13 fail); fullDasMaaPiTest66/0 on mingw.Tracking: DAS-84.