[xsd-users] BUG in generated code: Custom list type's
getDefaultValue() returns
twice the number of elements as its defined fixed size
Delker, Stefan
Stefan.Delker at kmweg.de
Mon Feb 18 09:47:52 EST 2019
Dear Sir or Madam,
we may have encountered a bug with the generated code based on the following example:
XSD:
<simpleType name="DISEntityType">
<restriction>
<simpleType>
<list itemType="unsignedShort"/>
</simpleType>
<length value="7" fixed="true"/>
</restriction>
</simpleType>
<element name="entityType" type="DISEntityType" minOccurs="0" default="0 0 0 0 0 0 0"/>
We're using the following generator flags:
--generate-serialization
--custom-type DISEntityType=/DISEntityType_impl
--hxx-epilogue-file Config-custom.inl
--generate-default-ctor
Our custom type implementation initializes the type by default having 7 elements, to guarantee all data is accessible:
class DISEntityType : public DISEntityType_impl
{
public:
DISEntityType () : DISEntityType_impl(DISEntityType_base(7, 0)) {}
...
inline uint32_t getKind() const { return uint32_t((*this)[0]); }
inline uint32_t getDomain() const { return uint32_t((*this)[1]); }
...(more getter)
inline void setKind(uint32_t i) { (*this)[0] = (i & 0xff); }
inline void setDomain(uint32_t i) { (*this)[1] = (i & 0xff); }
...(more setter)
}
While using the generated getEntityTypeDefaultValue(), the returned list contains 14 elements!
>From debugging the generated code, the default constructor already initializes the list with 7 elements.
The _xsd_entityType_default_value_init () adds seven elements to the default constructed object using (7 times):
{
::xml_schema::UnsignedShort tmp (0U);
r.push_back (tmp);
}
This explains the result of 14 elements (which is obviously wrong).
Is this actually a bug or are we misusing some feature of XSD?
>From our perspective, defining a default to be n times '0' in a type that is defined to have n elements should always result in having exactly n elements.
So maybe the default initialization should set its n elements to the given n values instead of adding them to an assumingly empty list?
Kind regards
[cid:image003.jpg at 01D326F2.C2DA1690]
Stefan Delker
Softwareentwickler | Software engineer
Training & Simulation
Krauss-Maffei Wegmann GmbH & Co. KG
Krauss-Maffei-Strasse 11
D-80997 Munich
Fon.: +49 89.8140.4895
stefan.delker at kmweg.de<mailto:stefan.delker at kmweg.de>
www.kmweg.de<http://www.kmweg.de/>
Krauss-Maffei Wegmann GmbH & Co. KG
Sitz der Gesellschaft ist Muenchen
Registergericht: Amtsgericht Muenchen, HRA 72 460
Persoenlich haftende Gesellschafterin: Krauss-Maffei Wegmann Verwaltungs GmbH
Sitz der Gesellschaft ist Muenchen
Registergericht: Amtsgericht Muenchen, HRB 118952
Geschaeftsfuehrer: Dipl.-Ing. Frank Haun (Vorsitzender), Dipl.-Ing. Ralf Ketzel, Dipl.-Kfm. Horst Rieder, Dipl.-Ing. Michael Ulverich
Vorsitzender des Aufsichtsrates: Dipl.-Ing. Dipl.-Wirtsch.-Ing. Axel J. Arendt.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 2295 bytes
Desc: image001.jpg
Url : https://codesynthesis.com/pipermail/xsd-users/attachments/20190218/7bd306cc/image001.jpg
More information about the xsd-users
mailing list