@@ -68,3 +68,41 @@ TEST(xml_regression, read_uint64_large_value) {
6868}
6969
7070} // namespace test_xml_reader_int64
71+
72+ // xml::Reader narrowing: stoull/stoll + static_cast<T> silently truncates
73+ // for types narrower than 64-bit (e.g. int16_t, uint16_t).
74+ namespace test_xml_reader_narrowing {
75+
76+ struct WithInt16 {
77+ int16_t value;
78+ };
79+
80+ struct WithUint16 {
81+ uint16_t value;
82+ };
83+
84+ TEST (xml_regression, read_rejects_out_of_range_for_int16) {
85+ const auto xml = std::string (
86+ " <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>"
87+ " <WithInt16><value>99999</value></WithInt16>" );
88+ const auto res = rfl::xml::read<WithInt16>(xml);
89+ EXPECT_FALSE (res) << " 99999 should be rejected for int16_t field" ;
90+ }
91+
92+ TEST (xml_regression, read_rejects_negative_for_uint16) {
93+ const auto xml = std::string (
94+ " <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>"
95+ " <WithUint16><value>-1</value></WithUint16>" );
96+ const auto res = rfl::xml::read<WithUint16>(xml);
97+ EXPECT_FALSE (res) << " -1 should be rejected for uint16_t field" ;
98+ }
99+
100+ TEST (xml_regression, read_rejects_large_negative_for_int16) {
101+ const auto xml = std::string (
102+ " <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>"
103+ " <WithInt16><value>-99999</value></WithInt16>" );
104+ const auto res = rfl::xml::read<WithInt16>(xml);
105+ EXPECT_FALSE (res) << " -99999 should be rejected for int16_t field" ;
106+ }
107+
108+ } // namespace test_xml_reader_narrowing
0 commit comments