public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110890] New: std::is_array and std::extent incorrectly choose a partial specialization when the size of an array exceeds INT32_MAX
@ 2023-08-03  9:03 y1079700998 at gmail dot com
  2023-08-03  9:10 ` [Bug c++/110890] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: y1079700998 at gmail dot com @ 2023-08-03  9:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110890
           Summary: std::is_array and std::extent incorrectly choose a
                    partial specialization when the size of an array
                    exceeds INT32_MAX
           Product: gcc
           Version: 9.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: y1079700998 at gmail dot com
  Target Milestone: ---

#include <type_traits>
#include <cstdint>
#include <iostream>

using T1 = char[1ul + INT32_MAX];

int main() {
    std::cout << std::is_array_v<T1> << '\n';
    std::cout << std::extent_v<T1, 0> << '\n';
}

When compiled with `g++ array_test.cpp -g -std=c++17 -Wall -Wextra
-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations
-fsanitize=undefined`, this script generates a result of "0 0". This behavior
was also observed with GCC 13.2 on godbolt.

When using clang++(tested with 10.0.0), however, the script generates the
expected result of "1 2147483648".

I discovered this behavior while performing some edge testing. It's probably
very rare to have an array of such a size in a real application.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/110890] std::is_array and std::extent incorrectly choose a partial specialization when the size of an array exceeds INT32_MAX
  2023-08-03  9:03 [Bug c++/110890] New: std::is_array and std::extent incorrectly choose a partial specialization when the size of an array exceeds INT32_MAX y1079700998 at gmail dot com
@ 2023-08-03  9:10 ` pinskia at gcc dot gnu.org
  2023-08-03  9:14 ` pinskia at gcc dot gnu.org
  2023-08-03  9:30 ` y1079700998 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-03  9:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
#include <cstdint>
using T1 = char[1ul + (unsigned long)INT32_MAX];


template <typename _Tp>
  inline constexpr bool is_array_v = false;
template <typename _Tp>
  inline constexpr bool is_array_v<_Tp[]> = true;
template <typename _Tp, unsigned long _Num>
  inline constexpr bool is_array_v<_Tp[_Num]> = true;

static_assert(is_array_v<T1>);
```

The question will T1 be a valid array definition?
For 32bit it is not. For 64bit it might be ...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/110890] std::is_array and std::extent incorrectly choose a partial specialization when the size of an array exceeds INT32_MAX
  2023-08-03  9:03 [Bug c++/110890] New: std::is_array and std::extent incorrectly choose a partial specialization when the size of an array exceeds INT32_MAX y1079700998 at gmail dot com
  2023-08-03  9:10 ` [Bug c++/110890] " pinskia at gcc dot gnu.org
@ 2023-08-03  9:14 ` pinskia at gcc dot gnu.org
  2023-08-03  9:30 ` y1079700998 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-03  9:14 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 88829.

*** This bug has been marked as a duplicate of bug 88829 ***

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/110890] std::is_array and std::extent incorrectly choose a partial specialization when the size of an array exceeds INT32_MAX
  2023-08-03  9:03 [Bug c++/110890] New: std::is_array and std::extent incorrectly choose a partial specialization when the size of an array exceeds INT32_MAX y1079700998 at gmail dot com
  2023-08-03  9:10 ` [Bug c++/110890] " pinskia at gcc dot gnu.org
  2023-08-03  9:14 ` pinskia at gcc dot gnu.org
@ 2023-08-03  9:30 ` y1079700998 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: y1079700998 at gmail dot com @ 2023-08-03  9:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Kaiyuan Yang <y1079700998 at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> Dup of bug 88829.
> 
> *** This bug has been marked as a duplicate of bug 88829 ***

Ah, thanks for the quick reply! Also, my apologies for the trouble.(I only
searched with "is_array" and "extent".)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-03  9:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-03  9:03 [Bug c++/110890] New: std::is_array and std::extent incorrectly choose a partial specialization when the size of an array exceeds INT32_MAX y1079700998 at gmail dot com
2023-08-03  9:10 ` [Bug c++/110890] " pinskia at gcc dot gnu.org
2023-08-03  9:14 ` pinskia at gcc dot gnu.org
2023-08-03  9:30 ` y1079700998 at gmail 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).