public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104699] New: zero-length-array is not considered as an array
@ 2022-02-26 13:58 nickhuang99 at hotmail dot com
2022-02-26 20:07 ` [Bug c++/104699] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: nickhuang99 at hotmail dot com @ 2022-02-26 13:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699
Bug ID: 104699
Summary: zero-length-array is not considered as an array
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nickhuang99 at hotmail dot com
Target Milestone: ---
GCC clearly states that "declaring zero-length arrays is allowed in GNU C as an
extension". https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
However, parser rejects to recognize int[0] as an array. i.e.
static_assert(! std::is_array<int[0]>::value);
This is not an issue of library function "is_array". Instead it is the
specialization of "is_array<int[0]>" which is not considered valid.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/104699] zero-length-array is not considered as an array
2022-02-26 13:58 [Bug c++/104699] New: zero-length-array is not considered as an array nickhuang99 at hotmail dot com
@ 2022-02-26 20:07 ` redi at gcc dot gnu.org
2022-02-26 21:36 ` nickhuang99 at hotmail dot com
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-26 20:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2022-02-26
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It says GNU C, not C++. But in any case, that example works fine for me, as
does the simpler:
template<typename T> struct S { };
S<int[0]> s;
Please provide the info you were asked to provide by https://gcc.gnu.org/bugs
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/104699] zero-length-array is not considered as an array
2022-02-26 13:58 [Bug c++/104699] New: zero-length-array is not considered as an array nickhuang99 at hotmail dot com
2022-02-26 20:07 ` [Bug c++/104699] " redi at gcc dot gnu.org
@ 2022-02-26 21:36 ` nickhuang99 at hotmail dot com
2022-02-28 9:45 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: nickhuang99 at hotmail dot com @ 2022-02-26 21:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699
qingzhe huang <nickhuang99 at hotmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nickhuang99 at hotmail dot com
--- Comment #2 from qingzhe huang <nickhuang99 at hotmail dot com> ---
(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<typename T> struct S { };
> S<int[0]> s;
>
> Please provide the info you were asked to provide by https://gcc.gnu.org/bugs
https://www.godbolt.org/z/8xa1dTzdM
#include <type_traits>
static_assert( ! std::is_array<int[0]>::value);
And as a directly result, it causes "make_shared" fails with "int[0]"
https://www.godbolt.org/z/8nE6qojaE
shared_ptr<int[0]> ptr=make_shared<int[0]>();
...
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<int[0]>" is
ill-format code or something.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/104699] zero-length-array is not considered as an array
2022-02-26 13:58 [Bug c++/104699] New: zero-length-array is not considered as an array nickhuang99 at hotmail dot com
2022-02-26 20:07 ` [Bug c++/104699] " redi at gcc dot gnu.org
2022-02-26 21:36 ` nickhuang99 at hotmail dot com
@ 2022-02-28 9:45 ` redi at gcc dot gnu.org
2022-02-28 9:58 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-28 9:45 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/104699] zero-length-array is not considered as an array
2022-02-26 13:58 [Bug c++/104699] New: zero-length-array is not considered as an array nickhuang99 at hotmail dot com
` (2 preceding siblings ...)
2022-02-28 9:45 ` redi at gcc dot gnu.org
@ 2022-02-28 9:58 ` redi at gcc dot gnu.org
2022-02-28 11:24 ` redi at gcc dot gnu.org
2022-03-01 1:55 ` nickhuang99 at hotmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-28 9:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The std::is_array result is a consequence of the compiler not matching the
is_array<T[N]> partial specialization for int[0]:
using size_t = decltype(sizeof(0));
template<typename T> struct X { static constexpr bool value = false; };
template<typename T, size_t N> struct X<T[N]> { static constexpr bool value =
true; };
static_assert( ! X<int[0]>::value );
GCC, Clang, Intel and MSVC all agree here: the int[0] type does not match the
X<T[N]> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/104699] zero-length-array is not considered as an array
2022-02-26 13:58 [Bug c++/104699] New: zero-length-array is not considered as an array nickhuang99 at hotmail dot com
` (3 preceding siblings ...)
2022-02-28 9:58 ` redi at gcc dot gnu.org
@ 2022-02-28 11:24 ` redi at gcc dot gnu.org
2022-03-01 1:55 ` nickhuang99 at hotmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-28 11:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(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<T[N]> partial specialization.
Although they don't agree for std::is_array, because libc++ uses Clang's
__is_array instrinsic.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/104699] zero-length-array is not considered as an array
2022-02-26 13:58 [Bug c++/104699] New: zero-length-array is not considered as an array nickhuang99 at hotmail dot com
` (4 preceding siblings ...)
2022-02-28 11:24 ` redi at gcc dot gnu.org
@ 2022-03-01 1:55 ` nickhuang99 at hotmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: nickhuang99 at hotmail dot com @ 2022-03-01 1:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104699
--- Comment #6 from qingzhe huang <nickhuang99 at hotmail dot com> ---
Really appreciate the detailed explanation!
Very clear and completely convinced.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-03-01 1:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-26 13:58 [Bug c++/104699] New: zero-length-array is not considered as an array nickhuang99 at hotmail dot com
2022-02-26 20:07 ` [Bug c++/104699] " redi at gcc dot gnu.org
2022-02-26 21:36 ` nickhuang99 at hotmail dot com
2022-02-28 9:45 ` redi at gcc dot gnu.org
2022-02-28 9:58 ` redi at gcc dot gnu.org
2022-02-28 11:24 ` redi at gcc dot gnu.org
2022-03-01 1:55 ` nickhuang99 at hotmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).