[Bug c++/104699] zero-length-array is not considered as an array
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699 --- Comment #6 from qingzhe huang --- Really appreciate the detailed explanation! Very clear and completely convinced.
[Bug c++/104699] zero-length-array is not considered as an array
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699 --- Comment #5 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #4) > GCC, Clang, Intel and MSVC all agree here: the int[0] type does not match > the X partial specialization. Although they don't agree for std::is_array, because libc++ uses Clang's __is_array instrinsic.
[Bug c++/104699] zero-length-array is not considered as an array
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699 --- Comment #4 from Jonathan Wakely --- The std::is_array result is a consequence of the compiler not matching the is_array partial specialization for int[0]: using size_t = decltype(sizeof(0)); template struct X { static constexpr bool value = false; }; template struct X { static constexpr bool value = true; }; static_assert( ! X::value ); GCC, Clang, Intel and MSVC all agree here: the int[0] type does not match the X partial specialization. I don't think it would be reasonable for the library to work differently, and I don't think it's reasonable to add kluges to make_shared to support creating an object of a type that should only exist as a subobject of some other object.
[Bug c++/104699] zero-length-array is not considered as an array
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699 Jonathan Wakely 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 --- (In reply to qingzhe huang from comment #2) > This is the direct result of template specialization "is_array" is > ill-format code or something. No it's not ill-formed, as shown by the fact that is_array::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 #include using namespace std; static_assert( ! std::is_array::value); shared_ptr ptr=make_shared(); This doesn't fail because is_array 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, 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 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(n) as equivalent to make_shared(n) and create a dynamically-sized array, but why bother? Just use int[] instead.
[Bug c++/104699] zero-length-array is not considered as an array
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699 qingzhe huang changed: What|Removed |Added CC||nickhuang99 at hotmail dot com --- Comment #2 from qingzhe huang --- (In reply to Jonathan Wakely from comment #1) > It says GNU C, not C++. But in any case, that example works fine for me, as > does the simpler: > > template struct S { }; > S s; > > Please provide the info you were asked to provide by https://gcc.gnu.org/bugs https://www.godbolt.org/z/8xa1dTzdM #include static_assert( ! std::is_array::value); And as a directly result, it causes "make_shared" fails with "int[0]" https://www.godbolt.org/z/8nE6qojaE shared_ptr ptr=make_shared(); ... error: request for member '~int [0]' in '* __location', which is of non-class type 'int [0]' 88 | __location->~_Tp(); | ~^~~ This is the direct result of template specialization "is_array" is ill-format code or something.
[Bug c++/104699] zero-length-array is not considered as an array
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |WAITING Last reconfirmed||2022-02-26 Ever confirmed|0 |1 --- Comment #1 from Jonathan Wakely --- It says GNU C, not C++. But in any case, that example works fine for me, as does the simpler: template struct S { }; S s; Please provide the info you were asked to provide by https://gcc.gnu.org/bugs