Hi crashpad-ians,
minidump/ contains a bunch of structures that are defined with a trailing zero-sized array.
On Windows/MSVC there's 3 problems that I've encountered with this so far from least bothersome to most bothersome. Soliciting suggestions (sorry for the long mail):
1. There's a warning emitted that the copy operators won't be correct, and it can't be disabled on the command line (i.e. build/common.gypi). This appears to be a compiler bug.
https://connect.microsoft.com/VisualStudio/feedback/details/1114440 . The pragma equivalent works though, so just requires ugly additions to the code, not a huge problem.
2. The zero length array cannot appear in other than last position, e.g:
d:\src\x>type x.cc
#pragma warning(disable: 4200)
struct X {
int wee[0];
int y;
};
d:\src\x>cl /nologo /c /W4 x.cc
x.cc
x.cc(4) : error C2229: struct 'X' has an illegal zero-sized array
This pattern occurs in minidump in a bunch of the Writer classes. Note that the error is emitted for the "int y;" line, which hints at the problem. It feels that array[0] have an invalid size, not zero size, so it can calculate the offset for subsequent elements.
These can be avoided by reordering members. e.g. in
MinidumpLocationDescriptorListWriter, the "MinidumpLocationDescriptorList location_descriptor_list_base_" member can be put in the last position and then it doesn't complain. This doesn't seem too bad.
3. Base classes cannot contain zero-sized arrays.
d:\src\x>type x.cc
#pragma warning(disable: 4200)
struct X {
int y;
int wee[0];
};
struct Z final : public X {
};
d:\src\x>cl /nologo /c /W4 x.cc
x.cc
x.cc(7) : error C2503: 'X' : base classes cannot contain zero-sized arrays
Note that this happens even when there's no members in the derived class. This comes up in minidump_string_writer.h and others.
I'm not sure what the best solution to this is. As-yet untested possibilities:
- remove inheritance in these cases and contain the base object with manual forwarding methods. [[ I didn't investigate how frequently the derived objects are stored into base class pointers ]]
- convert base classes to holding a scoped_ptr of the object with a zero-sized array. [[ This might reduce the benefit of having the object be contained, or otherwise be a bit awkward. ]]
Any suggestions or preferences? Otherwise I'll just poke at individual cases.