https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=104706

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to qingzhe huang from comment #2)
> This is the direct result of template specialization "is_array<int[0]>" is
> ill-format code or something.

No it's not ill-formed, as shown by the fact that is_array<int[0]>::value
compiles perfectly fine. You just don't like the result of that trait, but that
doesn't make it invalid or ill-formed.


> https://www.godbolt.org/z/8nE6qojaE

Please read https://gcc.gnu.org/bugs again, which asks for the code to be
provided *here* not via a URL.

This is the code from the second godbolt.org link:

#include <type_traits>
#include <memory>

using namespace std;

static_assert( ! std::is_array<int[0]>::value);

shared_ptr<int[0]> ptr=make_shared<int[0]>();

This doesn't fail because is_array<int[0]> is ill-formed, it fails because
int[0] is neither an unbounded array (like int[]) nor an array with non-zero
bound (like int[1]). That means we treat it as a non-array, which then fails to
compile because it can't be destroyed using a pseudo-destructor.

I don't see any need to support make_shared<int[0]>, it's not a valid type
according to the C++ type system, and is only useful as a member of a struct.
As I said at PR 104706, this is useless and you wouldn't be able to do anything
with shared_ptr<int[0]> even if you could create it.

The restrictions on C99 flexible array members are relevant here:

- Flexible array members have incomplete type, and so the sizeof operator may
not be applied. As a quirk of the original implementation of zero-length
arrays, sizeof evaluates to zero.
- Flexible array members may only appear as the last member of a struct that is
otherwise non-empty.

We *could* treat make_shared<int[0]>(n) as equivalent to make_shared<int[]>(n)
and create a dynamically-sized array, but why bother? Just use int[] instead.

Reply via email to