libc++: Zero length arrays in test code

There are numerous tests which use them such as:

std/containers/associative/map/map.special/member_swap.pass.cpp

typedef std::pair<const int, double> V;
typedef std::map<int, double> M;
{
V ar1[] =
{ };
V ar2[] =
{ };
M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));

These are non-standard GNU extensions, even in C++11 (as far as I read the standard at least). Would there be objection to changing the test code here to be standard conformant? My specific interest is MSVC, which can’t compile this.

If it is essential to test empty arrays then a couple of choices would be:

V* ar1 = nullptr;
M m1(ar1, ar1);

(I’m not sure I like this as it is a little white box, in the sense you assume that ar1 being null (or garbage) is okay because you know it’ll never get used).

or

V ar1[] = { V() };

M m1(ar1, ar1);

(At least ar1 points to something valid).

If anyone in WG21 (Chandler?) is reading this, it would be great to have this omission fixed in C++17 - it’s currently a big interoperability problem for using C headers from C++. Even if they were explicitly not permitted in classes that were used in inheritance, it would be a big help.

David

Would there be objection to changing the test code here to be standard conformant?

No, in fact it would be preferred. I thought I had already removed all
of the occurances of ZLA's :frowning:

If you want to put together a patch I'll review it ASAP.

/Eric

Will do so once I get a moment. Thanks!

>
> These are non-standard GNU extensions, even in C++11 (as far as I read
the standard at least).

If anyone in WG21 (Chandler?) is reading this, it would be great to have
this omission fixed in C++17 - it’s currently a big interoperability
problem for using C headers from C++.

It's a constraint violation in C, too.

Ach! Looks like you already fixed them all Eric. Sorry, my code is frozen on a particular revision whilst I get this stuff working for Windows. I had old code. Looks like you got them all!

Andrew

Hurry :slight_smile: Thanks for all of the windows work.