[cfe-dev] libc++: Zero length arrays in test code

Andrew Parker andrew.j.c.parker at gmail.com
Mon Jul 13 22:29:44 PDT 2015


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).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150714/1d9da957/attachment.html>


More information about the cfe-dev mailing list