You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Across the 7 rfl::xml gaps surfaced by cppcheck#3, which pieces are straightforward bugs to fix immediately versus API/policy choices that belong in a prototype, and how do they interact with existing XML PRs #66 and #71?
Wayfinder Resolution: Audit of rfl::xml 7-Gap Surface (cppcheck#3)
Audited against showcase/all-lanes (3d6a95b2, which already merges #71 at 1cd25faa, #66 at f1e08171, and error-kind at 0bca03ea) and real-world SSOT usage in clockblocker/cppcheck#3 (lib/schemas.h, lib/suppressions.cpp, lib/platform.cpp, lib/importproject.cpp, gui/projectfile.cpp).
(Note: cppcheck#3 also noted heavy template instantiation across TUs for large schemas when helpers are eager non-template inline functions; consumer-side lazy templates isolate TU cost, while moving Attribute onto TransparentWrapper in Gap #2 directly reduces per-field Parser instantiation bloat.)
Detailed Root-Cause Audit (All 7 Gaps)
1. rfl::NoExtraFields fails in 3 separate paths in rfl::xml::Reader
Where: include/rfl/xml/Reader.hpp:196-214 (Reader::read_object), interacting with include/rfl/parsing/ViewReader.hpp:146-150,215-228, include/rfl/parsing/ViewReaderWithDefault.hpp:204-211,218-228, and include/rfl/parsing/is_view_reader.hpp:19-21.
The 3 failure paths:
Unconditional synthetic "xml_content" emission (Reader.hpp:208-211): if constexpr (parsing::is_view_reader_v<ObjectReader>) unconditionally calls _object_reader.read("xml_content", InputVarType(_obj.node_)). Any struct without an xml_content field leaves already_assigned == false and fails with ErrorKind::unknown_field ("Value named 'xml_content' not used.").
Collateral bugs found: (a) is_view_reader_v (is_view_reader.hpp:19-21) only matches ViewReader, not ViewReaderWithDefault — so xml_content silently stops working whenever DefaultIfMissing or DefaultVal is used; (b) with rfl::ExtraFields, "xml_content" leaks into ExtraFields.
Non-element child nodes dispatched with empty name "" (Reader.hpp:198-201): for (auto child = _obj.node_.first_child(); child; child = child.next_sibling()) does not filter child.type() == pugi::node_element. Text (node_pcdata — present in every element with text content or parse_ws_pcdata), node_cdata, and node_comment (e.g. under pugi::parse_full via #66) all have child.name() == "" (and node_pi is not an element), triggering ErrorKind::unknown_field ("Value named '' not used.") under NoExtraFields and inserting empty keys into ExtraFields/MapReader.
Repeated sibling elements for XML array/vector fields rejected on 2nd+ occurrence (Reader.hpp:198-201): XML encodes sequences as repeated same-named sibling elements (<suppress/>, <suppress/>). On the 1st sibling, ViewReader marks found[i] = true and Reader::read_array (Reader.hpp:178) consumes all same-named siblings via node.next_sibling(name). read_object's outer loop then visits the 2nd+ sibling anyway; because found[i] is already true, both ViewReader::assign_if_field_matches (ViewReader.hpp:146) and ViewReaderWithDefault::assign_to_matching_field (ViewReaderWithDefault.hpp:204) skip assignment, leaving already_assigned == false and firing ErrorKind::unknown_field ("Value named '<tag>' not used.") on every array with >1 element (and spilling 2nd+ elements into ExtraFields).
cppcheck#3 evidence: Forced manual element allowlists in lib/schemas.h:332-398 (<project>, <safe-checks>) and lib/suppressions.cpp:183-197 (<suppress>).
Minimal fix:
Skip non-element children: if (child.type() != pugi::node_element) continue; in Reader::read_object.
Deduplicate already-seen sibling element names before calling _object_reader.read(...) when ObjectReader is a view reader (ViewReader or ViewReaderWithDefault; also check FieldVariantReader, while not deduplicating MapReader so std::multimap continues working). Use an O(1) immediate-previous-sibling fast path + small stack buffer (std::array<std::string_view, 16>) with std::unordered_set<std::string_view> fallback so large lists stay O(N) without heap allocation for typical structs. (Note: duplicate scalar tags under NoExtraFields follow first-wins semantics, separate from NoDuplicateKeys, which xml::Reader does not yet opt into.)
Extend is_view_reader (or add is_any_view_reader_v) to cover both ViewReader and ViewReaderWithDefault, and only emit "xml_content" when ObjectReader::ViewType::Fields actually declares a matching field at compile time.
2. std::optional<rfl::Attribute<T>> silently degrades to child element & rfl::Attribute<std::optional<T>> breaks JSON Schema required
Half A (std::optional<Attribute<T>> -> child element): is_attribute_v<T> (is_attribute.hpp:21) only peels a single outer Rename via remove_rename_t<T>. Any wrapping around Attribute<T> (std::optional, std::unique_ptr, std::shared_ptr, Box, Ref, DefaultVal, Description, Deprecated, Short, Positional, Skip, TransparentWrapper, or nested Rename<..., std::optional<Attribute<T>>>) evaluates is_attribute_v to false. NamedTupleParser::add_field_to_object (NamedTupleParser.hpp:276,286) omits .as_attribute(), so Writer::add_value_to_object_impl (Writer.cpp:94-105) emits <field>val</field> instead of field="val" (and under NoOptionals, add_null_to_object at Writer.cpp:133-141 emits an empty <field/> element instead of omitting it).
Half B (Attribute<std::optional<T>> -> broken JSON Schema required + $defs pollution): rfl::Attribute<T> (Attribute.hpp:21-24) does not set is_transparent_wrapper_ = true (nor inherit TransparentWrapper), so Parser::to_schema skips is_transparent_wrapper_v<U> (Parser_default.hpp:592) and falls through to has_reflection_type_v<U> (Parser_default.hpp:661-664) -> make_reference<U>(_definitions). That emits schema::Type::Reference{"Attribute<optional<...>>"} (polluting $defs) instead of schema::Type::Optional. In src/rfl/json/to_schema.cpp:37-55, is_optional returns false for Reference, so line 298 pushes every Attribute<std::optional<T>> field into "required": [...] — directly contradicting rfl::json::write, which omits std::nullopt because is_required (include/rfl/parsing/is_required.hpp:56-59) does recurse through ReflectionType.
Minimal fix:
Make is_attribute recursive across single-value wrapper/nullable types (Rename, std::optional, std::unique_ptr, std::shared_ptr, Box, Ref, DefaultVal, Description, Deprecated, Short, Positional, Skip, TransparentWrapperType) — matching is_default_val_v (include/rfl/internal/is_default_val_v.hpp:30-50). Ensure Attribute<T> matches before any TransparentWrapperType recursion.
Add static constexpr bool is_transparent_wrapper_ = true; to rfl::Attribute<T> (or rebase onto TransparentWrapper while preserving Attribute's existing cross-type Attribute<U> constructors/assignments for backward compatibility). This single trait fixes Parser_default.hpp:592 (to_schema unwraps Attribute inline -> restores Optional & removes bogus $defs/Attribute<...>), enables peel_transparent (peel_transparent_wrappers.hpp:39) on read, and wires Attribute into is_default_val_v and rfl::unwrap.
3. rfl::xml::read ignores the root element tag name
Where: include/rfl/xml/read.hpp:44-58 (read(const pugi::xml_node&)) and 67-75 (read(const std::string_view)).
Root cause: read(const pugi::xml_node&) selects the first pugi::node_element child of a node_document (read.hpp:49-53) and forwards straight to Parser::read without validating child.name(). rfl::xml::read<PlatformSchema>("<wrong/>") silently succeeds. cppcheck#3 had to manually load with pugixml and check root.name() in lib/schemas.h:68-70,327-330.
4. Magic "xml_content" field name leaks into JSON & JSON Schema
Root cause: XML text content is identified by serialized field name rather than by a transparent type wrapper. In cppcheck#3 (lib/schemas.h:243), ProjectSuppressionSchema had to declare rfl::Rename<"xml_content", std::optional<std::string>> errorId;, leaking "xml_content" into JSON serialization and JSON Schema instead of "errorId".
5. Empty self-closing XML tags (<check-headers/>, <max-ctu-depth/>) fail numeric/bool casts
Where: include/rfl/xml/Reader.hpp:97-102 (is_empty), 111-157 (to_basic_type), and include/rfl/parsing/ParserOptional.hpp:52-60.
Root cause: For <tag/>, pugixml yields a valid pugi::xml_node with child_value() == "". Reader::is_empty checks only !_node (null handle) -> false. ParserOptional::read therefore invokes Reader::to_basic_type, which fails on "" for bool (Reader.hpp:132), floating point (Reader.hpp:140), and integers (Reader.hpp:150).
Critical constraint observed in cppcheck#3 (lib/schemas.h:39,251-254,297-300,400-413):
Simply making Reader::is_empty return true for empty elements would break presence-marker tags (<class-public/>, <check-level-exhaustive/> modeled as std::optional<EmptyElement>, which rely on is_empty == false to decode as engaged EmptyElement{}) and empty strings (<builddir/> as std::optional<std::string>("")).
Moreover, ProjectFileSchema actually needed three distinct policies on the same struct:
<check-headers/>, <check-unused-templates/>, <inline-suppression/> (std::optional<bool>) -> false (Settings defaults to true when omitted, so <check-headers/> must be engaged false, not std::nullopt).
<analyze-all-vs-configs/> (std::optional<bool>) -> true in CLI, false in GUI.
Where: include/rfl/xml/write.hpp:99-129 and include/rfl/xml/save.hpp:23-30.
Root cause:
write(obj, stream, _indent) hardcodes doc.save(_stream, _indent.c_str()) (write.hpp:111) with no flags parameter and unconditionally appendspugi::node_declaration (write.hpp:105-107).
save (save.hpp:25-29) forwards neither _indent nor formatting flags.
Critical pugixml gotcha: pugi::format_no_declaration (pugixml.hpp:283) only suppresses pugixml's auto-generated declaration when none exists — it does not suppress an explicitly appended pugi::node_declaration child! Any implementation supporting format_no_declaration must guard doc.append_child(pugi::node_declaration) with if ((flags & pugi::format_no_declaration) == 0).
cppcheck#3 evidence: lib/schemas.h:143-160 (writeDumpSuppressionsXml) had to build a pugi::xml_document, call #66's write<"suppressions">(s, doc), invoke doc.save(oss, " ", pugi::format_default | pugi::format_no_declaration), and manually prepend " " to every line (which pugi::xml_node::print(..., depth) at pugixml.hpp:784 supports natively).
7. Empty document vs declaration-only XML conflation + missing ErrorKind classification
Where: include/rfl/xml/read.hpp:44-58,67-75 and include/rfl/xml/Reader.hpp:77,89,132,140,150,255.
Root cause:
In pugixml, doc.load_buffer(...) returns pugi::status_no_document_element ("No document element found") identically for empty/whitespace-only input ("", " \n"), declaration-only XML ("<?xml version=\"1.0\"?>"), and comment-only XML ("<!-- ... -->").
read.hpp:70-73 catches !result uniformly, conflating empty documents with declaration-only documents and making read.hpp:55 ("XML document has no root element.") unreachable from read(std::string_view). cppcheck#3 had to pre-scan whitespace with std::all_of(..., std::isspace) in both lib/schemas.h:310-320 and lib/suppressions.cpp:162-174.
Additionally, include/rfl/xml/ has zero ErrorKind tags on showcase/all-lanes (every XML parse/type/value error falls back to ErrorKind::other).
Filter child.type() != pugi::node_element in Reader::read_object.
Deduplicate repeated sibling element names in Reader::read_object for ViewReader / ViewReaderWithDefault (preserving MapReader / std::multimap, O(N) worst-case with zero-alloc fast path).
Extend is_view_reader_v (or add is_any_view_reader_v) to cover ViewReaderWithDefault and only emit "xml_content" when the target ViewType declares an "xml_content" field.
Regression tests: NoExtraFields with plain structs, structs with text content / comments (parse_full), structs with multi-element std::vector<T>, DefaultIfMissing + xml_content, and ExtraFields without "xml_content" / duplicate-sibling leakage.
Make rfl::internal::is_attribute recursive across nullable/metadata wrappers (std::optional, unique_ptr, shared_ptr, Box, Ref, Rename, DefaultVal, Description, Deprecated, Short, Positional, Skip, TransparentWrapperType).
Add static constexpr bool is_transparent_wrapper_ = true; to rfl::Attribute<T> (preserving all existing constructors/assignments) so Parser::to_schema unwraps Attribute inline (fixing JSON Schema "required" and eliminating $defs/Attribute<...> pollution) and peel_transparent peels Attribute on read.
Regression tests: XML write/read round-trip for std::optional<Attribute<T>>, Rename<"x", std::optional<Attribute<T>>>, DefaultVal<Attribute<T>>, NoOptionals with empty std::optional<Attribute<T>>, and rfl::json::to_schema verifying neither Attribute<std::optional<T>> nor std::optional<Attribute<T>> lands in "required" or $defs.
Ticket 3 (small pure bugfix, can be standalone or bundled with ErrorKind XML follow-up) — Distinguish empty vs declaration-only XML & tag ErrorKind in rfl::xml:
In rfl::xml::read(std::string_view): detect empty/whitespace-only input ("XML document is empty.", ErrorKind::syntax_error) separately from status_no_document_element on non-empty prolog/comment-only input ("XML document has no root element.", ErrorKind::syntax_error) vs malformed syntax (ErrorKind::syntax_error).
Tag rfl::xml::Reader errors to match rfl::json::Reader & rfl::env::Reader: get_field_from_array / get_field_from_object -> ErrorKind::missing_field; to_basic_type lexical cast failures -> ErrorKind::invalid_value; cast_as_node on attribute -> ErrorKind::invalid_type.
(Per Error.hpp:48-51 and XML 1.0 well-formedness, both empty input and declaration-only XML are ErrorKind::syntax_error; distinct messages separate them cleanly without inventing a format-specific ErrorKind.)
B. API / Design Prototypes (for downstream Prototype rfl::xml ... ticket on showcase/all-lanes)
Recommended: Add NTTP overload template <internal::StringLiteral _root, class T, class... Ps> Result<T> read(...) (and load<"root", T, Ps...>) across pugi::xml_node, std::string_view, and std::istream.
Why: Unambiguous in C++20 against read<T, Ps...> (NTTP vs type first param), 100% backward-compatible, mirrors rfl::xml::write<"root">, and avoids multiplying Parser<..., ProcessorsType> instantiations (unlike a RequireRoot<"root"> processor). Returns Error("Expected root element '<expected>', got '<actual>'.", ErrorKind::invalid_value) on mismatch. Optionally pair with a runtime-name overload or ReadOptions if dynamic root validation is desired.
Recommended: Introduce a transparent wrapper rfl::xml::Content<T> (or rfl::Content<T> in <rfl/XmlContent.hpp> / <rfl/Attribute.hpp>, zero pugixml dependency so SSOT headers stay lightweight) with is_transparent_wrapper_ = true and ReflectionType = T, plus recursive is_xml_content_v<T>.
Wiring:
JSON / YAML / TOML / JSON Schema see the field's normal C++ (or Rename) name ("errorId"), never "xml_content".
XML Reader::read_object locates the is_xml_content_v field at compile time (falling back to legacy "xml_content" for full backward compatibility) and dispatches _object_reader.read(field_name, InputVarType(_obj.node_)).
XML Writer path: mark Parent::Object with is_xml_content_ (or pass "xml_content" to Writer::add_value_to_object/add_null_to_object when is_xml_content_v<ValueType> for zero ABI change to RFL_API Writer, or add an additive add_content_to_object). Static-assert at most one content field per struct and disallow combining Attribute + Content on one field.
Trade-off vs alternatives: Rename leaks across formats; external struct traits break Flatten/field locality.
Struct-wide opt-in processors for uniform schemas:
rfl::xml::EmptyAsNull: scoped to scalar/basic leaf elements (no child elements/attributes, empty child_value()), so std::optional<int> on <max-ctu-depth/> decodes as std::nullopt while std::optional<EmptyElement> on <class-public/> stays engaged!
rfl::xml::EmptyAsDefault: in scalar to_basic_type, "" decodes as T{} (false / 0 / 0.0).
Per-field policy for mixed-semantics legacy schemas (like ProjectFileSchema, where <max-ctu-depth/> -> nullopt, <check-headers/> -> false, <analyze-all-vs-configs/> -> true coexist in one struct): either a tiny transparent wrapper rfl::xml::EmptyValue<T, Val> / rfl::xml::EmptyAsNullField<T>, or document #66's from_xml_obj as the blessed escape hatch for per-field quirks.
Trade-off: Testing both EmptyAsNull/EmptyAsDefault processors and a per-field wrapper against cppcheck#3's ProjectFileSchema will cleanly show whether the per-field wrapper earns its API surface over from_xml_obj.
Extend write(obj, _stream, _indent = " ", unsigned int _flags = pugi::format_default) and write(obj, _indent = " ", unsigned int _flags = pugi::format_default) (parallel to rfl::json::write(obj, yyjson_write_flag)), guarding doc.append_child(pugi::node_declaration) on (_flags & pugi::format_no_declaration) == 0.
Add an optional rfl::xml::WriteOptions overload (indent, flags, initial_depth = 0) using pugi::xml_node::print(_stream, indent, flags, encoding_auto, initial_depth) when initial_depth > 0 && (flags & pugi::format_no_declaration) — eliminating cppcheck#3's manual line-prefix loop in writeDumpSuppressionsXml.
Forward _indent / _flags (or WriteOptions) in rfl::xml::save.
Interaction Map
Neighbor
Relationship / Coordination Required
PR #66 (xml-pugixml, merged in showcase/all-lanes)
Already adds read(const pugi::xml_node&), write(obj, pugi::xml_node[, root_name]), and T::from_xml_obj. Gap #1 Path B is amplified by #66 (users passing pugi::parse_full DOMs with comments/PIs). Gap #3 (read<"root", T>(node)) should overload cleanly on #66's pugi::xml_node entry point. Gap #6's write flags/WriteOptions have zero overload ambiguity with #66's pugi::xml_node overloads. Gap #5's per-field legacy quirks can also leverage #66's from_xml_obj.
PR #71 (fix-xml-array-and-indent, merged in showcase/all-lanes)
Fixed get_field_from_array (++i) and write(obj, _indent) forwarding. Gap #6 must preserve write(obj, " ") and write(obj, stream, " ") signatures added/fixed in #71 without ambiguity.
Lane 1 (TransparentWrapper / recursive wrapper peeling)
Gap #2 directly completes Lane 1's wrapper uniformity for XML: marking rfl::Attribute<T> with is_transparent_wrapper_ = true plugs it into peel_transparent_wrappers.hpp:39, Parser_default.hpp:592, is_default_val_v.hpp:48, and unwrap.hpp:23, and Gap #4's Content<T> should be built on TransparentWrapper from day one. Ensure is_attribute_v / is_xml_content_v check their own tag before recursing on TransparentWrapperType.
PR error-kind (merged in showcase/all-lanes)
Gap #7 brings include/rfl/xml/{read,Reader}.hpp up to parity with rfl::json and rfl::env by tagging syntax_error, missing_field, invalid_type, and invalid_value.
One-line Gist (for Lane 2 Map ## Decisions so far)
Audited all 7 rfl::xml gaps from cppcheck#3 on showcase/all-lanes: split into 3 pure bugfixes (NoExtraFields 3 paths in xml::Reader::read_object, Attribute recursive trait + TransparentWrapper schema fix, and empty-vs-declaration-only + ErrorKind tagging) and 4 opt-in API prototypes (read<"root", T>, transparent xml::Content<T>, scalar-scoped EmptyAsNull/EmptyAsDefault vs per-field policy, and pugixml write flags/WriteOptions guarding node_declaration).
Activity
clockblocker commentedon Nov 27, 2026
Wayfinder Resolution: Audit of
rfl::xml7-Gap Surface (cppcheck#3)Audited against
showcase/all-lanes(3d6a95b2, which already merges#71at1cd25faa,#66atf1e08171, anderror-kindat0bca03ea) and real-world SSOT usage inclockblocker/cppcheck#3(lib/schemas.h,lib/suppressions.cpp,lib/platform.cpp,lib/importproject.cpp,gui/projectfile.cpp).Summary Matrix
cppcheck#3showcase/all-lanes)rfl::NoExtraFieldsfails in 3 pathsready-for-agent)include/rfl/xml/Reader.hpp:196-214,include/rfl/parsing/is_view_reader.hpp:19-21std::optional<Attribute<T>>degrades to element &Attribute<std::optional<T>>breaks JSON Schemarequiredready-for-agent)include/rfl/internal/is_attribute.hpp:21,include/rfl/Attribute.hpp:21-24,include/rfl/parsing/Parser_default.hpp:592-596,661-664rfl::xml::readignores root element tag nameinclude/rfl/xml/read.hpp:44-58,67-75"xml_content"field leaks into JSON & JSON Schemainclude/rfl/xml/Reader.hpp:208-211,src/rfl/xml/Writer.cpp:33,97-99,135-136<check-headers/>,<max-ctu-depth/>) fail bool/numeric castsinclude/rfl/xml/Reader.hpp:97-102,111-157,include/rfl/parsing/ParserOptional.hpp:52-60rfl::xml::writelacks formatting flags (format_no_declaration, base indent/depth)include/rfl/xml/write.hpp:99-129,include/rfl/xml/save.hpp:23-30ErrorKindtaggingready-for-agent)include/rfl/xml/read.hpp:44-58,67-75,include/rfl/xml/Reader.hpp:77,89,132,140,150,255(Note:
cppcheck#3also noted heavy template instantiation across TUs for large schemas when helpers are eager non-templateinlinefunctions; consumer-side lazy templates isolate TU cost, while movingAttributeontoTransparentWrapperin Gap #2 directly reduces per-fieldParserinstantiation bloat.)Detailed Root-Cause Audit (All 7 Gaps)
1.
rfl::NoExtraFieldsfails in 3 separate paths inrfl::xml::Readerinclude/rfl/xml/Reader.hpp:196-214(Reader::read_object), interacting withinclude/rfl/parsing/ViewReader.hpp:146-150,215-228,include/rfl/parsing/ViewReaderWithDefault.hpp:204-211,218-228, andinclude/rfl/parsing/is_view_reader.hpp:19-21."xml_content"emission (Reader.hpp:208-211):if constexpr (parsing::is_view_reader_v<ObjectReader>)unconditionally calls_object_reader.read("xml_content", InputVarType(_obj.node_)). Any struct without anxml_contentfield leavesalready_assigned == falseand fails withErrorKind::unknown_field("Value named 'xml_content' not used.").is_view_reader_v(is_view_reader.hpp:19-21) only matchesViewReader, notViewReaderWithDefault— soxml_contentsilently stops working wheneverDefaultIfMissingorDefaultValis used; (b) withrfl::ExtraFields,"xml_content"leaks intoExtraFields.""(Reader.hpp:198-201):for (auto child = _obj.node_.first_child(); child; child = child.next_sibling())does not filterchild.type() == pugi::node_element. Text (node_pcdata— present in every element with text content orparse_ws_pcdata),node_cdata, andnode_comment(e.g. underpugi::parse_fullvia#66) all havechild.name() == ""(andnode_piis not an element), triggeringErrorKind::unknown_field("Value named '' not used.") underNoExtraFieldsand inserting empty keys intoExtraFields/MapReader.Reader.hpp:198-201): XML encodes sequences as repeated same-named sibling elements (<suppress/>,<suppress/>). On the 1st sibling,ViewReadermarksfound[i] = trueandReader::read_array(Reader.hpp:178) consumes all same-named siblings vianode.next_sibling(name).read_object's outer loop then visits the 2nd+ sibling anyway; becausefound[i]is alreadytrue, bothViewReader::assign_if_field_matches(ViewReader.hpp:146) andViewReaderWithDefault::assign_to_matching_field(ViewReaderWithDefault.hpp:204) skip assignment, leavingalready_assigned == falseand firingErrorKind::unknown_field("Value named '<tag>' not used.") on every array with >1 element (and spilling 2nd+ elements intoExtraFields).cppcheck#3evidence: Forced manual element allowlists inlib/schemas.h:332-398(<project>,<safe-checks>) andlib/suppressions.cpp:183-197(<suppress>).if (child.type() != pugi::node_element) continue;inReader::read_object._object_reader.read(...)whenObjectReaderis a view reader (ViewReaderorViewReaderWithDefault; also checkFieldVariantReader, while not deduplicatingMapReadersostd::multimapcontinues working). Use an O(1) immediate-previous-sibling fast path + small stack buffer (std::array<std::string_view, 16>) withstd::unordered_set<std::string_view>fallback so large lists stay O(N) without heap allocation for typical structs. (Note: duplicate scalar tags underNoExtraFieldsfollow first-wins semantics, separate fromNoDuplicateKeys, whichxml::Readerdoes not yet opt into.)is_view_reader(or addis_any_view_reader_v) to cover bothViewReaderandViewReaderWithDefault, and only emit"xml_content"whenObjectReader::ViewType::Fieldsactually declares a matching field at compile time.2.
std::optional<rfl::Attribute<T>>silently degrades to child element &rfl::Attribute<std::optional<T>>breaks JSON Schemarequiredinclude/rfl/internal/is_attribute.hpp:11-22&include/rfl/internal/remove_rename.hpp:15-27include/rfl/parsing/NamedTupleParser.hpp:276-292include/rfl/Attribute.hpp:21-24include/rfl/parsing/Parser_default.hpp:592-596,661-664,696-754src/rfl/json/to_schema.cpp:37-55,296-301std::optional<Attribute<T>>-> child element):is_attribute_v<T>(is_attribute.hpp:21) only peels a single outerRenameviaremove_rename_t<T>. Any wrapping aroundAttribute<T>(std::optional,std::unique_ptr,std::shared_ptr,Box,Ref,DefaultVal,Description,Deprecated,Short,Positional,Skip,TransparentWrapper, or nestedRename<..., std::optional<Attribute<T>>>) evaluatesis_attribute_vtofalse.NamedTupleParser::add_field_to_object(NamedTupleParser.hpp:276,286) omits.as_attribute(), soWriter::add_value_to_object_impl(Writer.cpp:94-105) emits<field>val</field>instead offield="val"(and underNoOptionals,add_null_to_objectatWriter.cpp:133-141emits an empty<field/>element instead of omitting it).Attribute<std::optional<T>>-> broken JSON Schemarequired+$defspollution):rfl::Attribute<T>(Attribute.hpp:21-24) does not setis_transparent_wrapper_ = true(nor inheritTransparentWrapper), soParser::to_schemaskipsis_transparent_wrapper_v<U>(Parser_default.hpp:592) and falls through tohas_reflection_type_v<U>(Parser_default.hpp:661-664) ->make_reference<U>(_definitions). That emitsschema::Type::Reference{"Attribute<optional<...>>"}(polluting$defs) instead ofschema::Type::Optional. Insrc/rfl/json/to_schema.cpp:37-55,is_optionalreturnsfalseforReference, so line298pushes everyAttribute<std::optional<T>>field into"required": [...]— directly contradictingrfl::json::write, which omitsstd::nulloptbecauseis_required(include/rfl/parsing/is_required.hpp:56-59) does recurse throughReflectionType.is_attributerecursive across single-value wrapper/nullable types (Rename,std::optional,std::unique_ptr,std::shared_ptr,Box,Ref,DefaultVal,Description,Deprecated,Short,Positional,Skip,TransparentWrapperType) — matchingis_default_val_v(include/rfl/internal/is_default_val_v.hpp:30-50). EnsureAttribute<T>matches before anyTransparentWrapperTyperecursion.static constexpr bool is_transparent_wrapper_ = true;torfl::Attribute<T>(or rebase ontoTransparentWrapperwhile preservingAttribute's existing cross-typeAttribute<U>constructors/assignments for backward compatibility). This single trait fixesParser_default.hpp:592(to_schemaunwrapsAttributeinline -> restoresOptional& removes bogus$defs/Attribute<...>), enablespeel_transparent(peel_transparent_wrappers.hpp:39) on read, and wiresAttributeintois_default_val_vandrfl::unwrap.3.
rfl::xml::readignores the root element tag nameinclude/rfl/xml/read.hpp:44-58(read(const pugi::xml_node&)) and67-75(read(const std::string_view)).read(const pugi::xml_node&)selects the firstpugi::node_elementchild of anode_document(read.hpp:49-53) and forwards straight toParser::readwithout validatingchild.name().rfl::xml::read<PlatformSchema>("<wrong/>")silently succeeds.cppcheck#3had to manually load withpugixmland checkroot.name()inlib/schemas.h:68-70,327-330.4. Magic
"xml_content"field name leaks into JSON & JSON Schemainclude/rfl/xml/Reader.hpp:208-211("xml_content")src/rfl/xml/Writer.cpp:33,97-99,135-136(XML_CONTENT = "xml_content")SnakeCaseToCamelCase.hpp:20,SnakeCaseToPascalCase.hpp:20,SnakeCaseToKebabCase.hpp:22,CamelCaseToSnakeCase.hpp:20,ToAllCaps.hpp:20)cppcheck#3(lib/schemas.h:243),ProjectSuppressionSchemahad to declarerfl::Rename<"xml_content", std::optional<std::string>> errorId;, leaking"xml_content"into JSON serialization and JSON Schema instead of"errorId".5. Empty self-closing XML tags (
<check-headers/>,<max-ctu-depth/>) fail numeric/bool castsinclude/rfl/xml/Reader.hpp:97-102(is_empty),111-157(to_basic_type), andinclude/rfl/parsing/ParserOptional.hpp:52-60.<tag/>,pugixmlyields a validpugi::xml_nodewithchild_value() == "".Reader::is_emptychecks only!_node(null handle) ->false.ParserOptional::readtherefore invokesReader::to_basic_type, which fails on""forbool(Reader.hpp:132), floating point (Reader.hpp:140), and integers (Reader.hpp:150).cppcheck#3(lib/schemas.h:39,251-254,297-300,400-413):Reader::is_emptyreturntruefor empty elements would break presence-marker tags (<class-public/>,<check-level-exhaustive/>modeled asstd::optional<EmptyElement>, which rely onis_empty == falseto decode as engagedEmptyElement{}) and empty strings (<builddir/>asstd::optional<std::string>("")).ProjectFileSchemaactually needed three distinct policies on the same struct:<max-ctu-depth/>,<max-template-recursion/>,<cert-c-int-precision/>(std::optional<int>) ->std::nullopt(preserve Cppcheck's default2/100, not0).<check-headers/>,<check-unused-templates/>,<inline-suppression/>(std::optional<bool>) ->false(Settings defaults totruewhen omitted, so<check-headers/>must be engagedfalse, notstd::nullopt).<analyze-all-vs-configs/>(std::optional<bool>) ->truein CLI,falsein GUI.6.
rfl::xml::writemissing formatting flags (format_no_declaration, custom indent prefix /pugixmlflags)include/rfl/xml/write.hpp:99-129andinclude/rfl/xml/save.hpp:23-30.write(obj, stream, _indent)hardcodesdoc.save(_stream, _indent.c_str())(write.hpp:111) with noflagsparameter and unconditionally appendspugi::node_declaration(write.hpp:105-107).save(save.hpp:25-29) forwards neither_indentnor formatting flags.pugixmlgotcha:pugi::format_no_declaration(pugixml.hpp:283) only suppresses pugixml's auto-generated declaration when none exists — it does not suppress an explicitly appendedpugi::node_declarationchild! Any implementation supportingformat_no_declarationmust guarddoc.append_child(pugi::node_declaration)withif ((flags & pugi::format_no_declaration) == 0).cppcheck#3evidence:lib/schemas.h:143-160(writeDumpSuppressionsXml) had to build apugi::xml_document, call#66'swrite<"suppressions">(s, doc), invokedoc.save(oss, " ", pugi::format_default | pugi::format_no_declaration), and manually prepend" "to every line (whichpugi::xml_node::print(..., depth)atpugixml.hpp:784supports natively).7. Empty document vs declaration-only XML conflation + missing
ErrorKindclassificationinclude/rfl/xml/read.hpp:44-58,67-75andinclude/rfl/xml/Reader.hpp:77,89,132,140,150,255.pugixml,doc.load_buffer(...)returnspugi::status_no_document_element("No document element found") identically for empty/whitespace-only input (""," \n"), declaration-only XML ("<?xml version=\"1.0\"?>"), and comment-only XML ("<!-- ... -->").read.hpp:70-73catches!resultuniformly, conflating empty documents with declaration-only documents and makingread.hpp:55("XML document has no root element.") unreachable fromread(std::string_view).cppcheck#3had to pre-scan whitespace withstd::all_of(..., std::isspace)in bothlib/schemas.h:310-320andlib/suppressions.cpp:162-174.include/rfl/xml/has zeroErrorKindtags onshowcase/all-lanes(every XML parse/type/value error falls back toErrorKind::other).Clean Action Split
A. Pure Bugfixes (
ready-for-agent)Ticket 1 — Fix
rfl::xml::ReaderNoExtraFields(all 3 paths) &ViewReaderWithDefaultxml_content:child.type() != pugi::node_elementinReader::read_object.Reader::read_objectforViewReader/ViewReaderWithDefault(preservingMapReader/std::multimap, O(N) worst-case with zero-alloc fast path).is_view_reader_v(or addis_any_view_reader_v) to coverViewReaderWithDefaultand only emit"xml_content"when the targetViewTypedeclares an"xml_content"field.NoExtraFieldswith plain structs, structs with text content / comments (parse_full), structs with multi-elementstd::vector<T>,DefaultIfMissing+xml_content, andExtraFieldswithout"xml_content"/ duplicate-sibling leakage.Ticket 2 — Fix
std::optional<rfl::Attribute<T>>&rfl::Attribute<std::optional<T>>(XML write + JSON Schema):rfl::internal::is_attributerecursive across nullable/metadata wrappers (std::optional,unique_ptr,shared_ptr,Box,Ref,Rename,DefaultVal,Description,Deprecated,Short,Positional,Skip,TransparentWrapperType).static constexpr bool is_transparent_wrapper_ = true;torfl::Attribute<T>(preserving all existing constructors/assignments) soParser::to_schemaunwrapsAttributeinline (fixing JSON Schema"required"and eliminating$defs/Attribute<...>pollution) andpeel_transparentpeelsAttributeon read.std::optional<Attribute<T>>,Rename<"x", std::optional<Attribute<T>>>,DefaultVal<Attribute<T>>,NoOptionalswith emptystd::optional<Attribute<T>>, andrfl::json::to_schemaverifying neitherAttribute<std::optional<T>>norstd::optional<Attribute<T>>lands in"required"or$defs.Ticket 3 (small pure bugfix, can be standalone or bundled with
ErrorKindXML follow-up) — Distinguish empty vs declaration-only XML & tagErrorKindinrfl::xml:rfl::xml::read(std::string_view): detect empty/whitespace-only input ("XML document is empty.",ErrorKind::syntax_error) separately fromstatus_no_document_elementon non-empty prolog/comment-only input ("XML document has no root element.",ErrorKind::syntax_error) vs malformed syntax (ErrorKind::syntax_error).rfl::xml::Readererrors to matchrfl::json::Reader&rfl::env::Reader:get_field_from_array/get_field_from_object->ErrorKind::missing_field;to_basic_typelexical cast failures ->ErrorKind::invalid_value;cast_as_nodeon attribute ->ErrorKind::invalid_type.Error.hpp:48-51and XML 1.0 well-formedness, both empty input and declaration-only XML areErrorKind::syntax_error; distinct messages separate them cleanly without inventing a format-specificErrorKind.)B. API / Design Prototypes (for downstream
Prototype rfl::xml ...ticket onshowcase/all-lanes)Gap Make optional and default-valued fields work inside rfl::Short, rfl::Positional and rfl::Description #3 — Root-tag validation (
rfl::xml::read<"root", T, Ps...>):template <internal::StringLiteral _root, class T, class... Ps> Result<T> read(...)(andload<"root", T, Ps...>) acrosspugi::xml_node,std::string_view, andstd::istream.read<T, Ps...>(NTTP vs type first param), 100% backward-compatible, mirrorsrfl::xml::write<"root">, and avoids multiplyingParser<..., ProcessorsType>instantiations (unlike aRequireRoot<"root">processor). ReturnsError("Expected root element '<expected>', got '<actual>'.", ErrorKind::invalid_value)on mismatch. Optionally pair with a runtime-name overload orReadOptionsif dynamic root validation is desired.Gap Add rfl::cli::BlankItemsAsMissing to keep blank list items #4 — Non-leaking XML text content wrapper (
rfl::xml::Content<T>/rfl::Content<T>):rfl::xml::Content<T>(orrfl::Content<T>in<rfl/XmlContent.hpp>/<rfl/Attribute.hpp>, zeropugixmldependency so SSOT headers stay lightweight) withis_transparent_wrapper_ = trueandReflectionType = T, plus recursiveis_xml_content_v<T>.Rename) name ("errorId"), never"xml_content".Reader::read_objectlocates theis_xml_content_vfield at compile time (falling back to legacy"xml_content"for full backward compatibility) and dispatches_object_reader.read(field_name, InputVarType(_obj.node_)).Writerpath: markParent::Objectwithis_xml_content_(or pass"xml_content"toWriter::add_value_to_object/add_null_to_objectwhenis_xml_content_v<ValueType>for zero ABI change toRFL_API Writer, or add an additiveadd_content_to_object). Static-assert at most one content field per struct and disallow combiningAttribute+Contenton one field.Renameleaks across formats; external struct traits breakFlatten/field locality.Gap Accept grouped short options and abbreviated long options in rfl::cli #5 — Opt-in empty self-closing element policies:
Reader::is_empty(<EmptyElement/>) == false:rfl::xml::EmptyAsNull: scoped to scalar/basic leaf elements (no child elements/attributes, emptychild_value()), sostd::optional<int>on<max-ctu-depth/>decodes asstd::nulloptwhilestd::optional<EmptyElement>on<class-public/>stays engaged!rfl::xml::EmptyAsDefault: in scalarto_basic_type,""decodes asT{}(false/0/0.0).ProjectFileSchema, where<max-ctu-depth/>->nullopt,<check-headers/>->false,<analyze-all-vs-configs/>->truecoexist in one struct): either a tiny transparent wrapperrfl::xml::EmptyValue<T, Val>/rfl::xml::EmptyAsNullField<T>, or document#66'sfrom_xml_objas the blessed escape hatch for per-field quirks.EmptyAsNull/EmptyAsDefaultprocessors and a per-field wrapper againstcppcheck#3'sProjectFileSchemawill cleanly show whether the per-field wrapper earns its API surface overfrom_xml_obj.Gap Accept repeated list options and remaining positional arguments in rfl::cli #6 — Formatting flags on
rfl::xml::write&rfl::xml::save:write(obj, _stream, _indent = " ", unsigned int _flags = pugi::format_default)andwrite(obj, _indent = " ", unsigned int _flags = pugi::format_default)(parallel torfl::json::write(obj, yyjson_write_flag)), guardingdoc.append_child(pugi::node_declaration)on(_flags & pugi::format_no_declaration) == 0.rfl::xml::WriteOptionsoverload (indent,flags,initial_depth = 0) usingpugi::xml_node::print(_stream, indent, flags, encoding_auto, initial_depth)wheninitial_depth > 0 && (flags & pugi::format_no_declaration)— eliminatingcppcheck#3's manual line-prefix loop inwriteDumpSuppressionsXml._indent/_flags(orWriteOptions) inrfl::xml::save.Interaction Map
#66(xml-pugixml, merged inshowcase/all-lanes)read(const pugi::xml_node&),write(obj, pugi::xml_node[, root_name]), andT::from_xml_obj. Gap #1 Path B is amplified by#66(users passingpugi::parse_fullDOMs with comments/PIs). Gap #3 (read<"root", T>(node)) should overload cleanly on#66'spugi::xml_nodeentry point. Gap #6'swriteflags/WriteOptionshave zero overload ambiguity with#66'spugi::xml_nodeoverloads. Gap #5's per-field legacy quirks can also leverage#66'sfrom_xml_obj.#71(fix-xml-array-and-indent, merged inshowcase/all-lanes)get_field_from_array(++i) andwrite(obj, _indent)forwarding. Gap #6 must preservewrite(obj, " ")andwrite(obj, stream, " ")signatures added/fixed in#71without ambiguity.TransparentWrapper/ recursive wrapper peeling)rfl::Attribute<T>withis_transparent_wrapper_ = trueplugs it intopeel_transparent_wrappers.hpp:39,Parser_default.hpp:592,is_default_val_v.hpp:48, andunwrap.hpp:23, and Gap #4'sContent<T>should be built onTransparentWrapperfrom day one. Ensureis_attribute_v/is_xml_content_vcheck their own tag before recursing onTransparentWrapperType.error-kind(merged inshowcase/all-lanes)include/rfl/xml/{read,Reader}.hppup to parity withrfl::jsonandrfl::envby taggingsyntax_error,missing_field,invalid_type, andinvalid_value.One-line Gist (for Lane 2 Map
## Decisions so far)