public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107735] New: Inconsistent error messages for std::array out of bound
@ 2022-11-17 15:00 andrzej at rpi dot pl
  2022-11-17 16:31 ` [Bug c++/107735] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: andrzej at rpi dot pl @ 2022-11-17 15:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107735
           Summary: Inconsistent error messages for std::array out of
                    bound
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrzej at rpi dot pl
  Target Milestone: ---

Created attachment 53919
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53919&action=edit
Preprocessed file

The second and third lines of following code produce different `out of bound`
compile errors, one pointing to the original line, the other pointing to a line
inside standard library that is trying to access internal (non-std::) array  

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
constexpr std::array<int, 3> array = {1, 2, 3};
constexpr int v1 = array[3];
constexpr int v2 = array[4];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Compilation line:
`g++-12 a-minimal_example.ii`

Compiler output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
minimal_example.cpp:6:27: error: array subscript value ‘3’ is outside the
bounds of array type ‘std::__array_traits<int, 3>::_Type’ {aka ‘const int [3]’}
    6 | constexpr int v1 = array[3];
      |                           ^
In file included from minimal_example.cpp:1:
minimal_example.cpp:9:27:   in ‘constexpr’ expansion of ‘array.std::array<int,
3>::operator[](4)’
/usr/include/c++/12/array:219:25:   in ‘constexpr’ expansion of
‘std::__array_traits<int, 3>::_S_ref(((const std::array<int,
3>*)this)->std::array<int, 3>::_M_elems, __n)’
/usr/include/c++/12/array:61:36: error: array subscript value ‘4’ is outside
the bounds of array type ‘std::__array_traits<int, 3>::_Type’ {aka ‘const int
[3]’}
   61 |       { return const_cast<_Tp&>(__t[__n]); }
      |                                 ~~~^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GCC version:
gcc-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0

System version:
Linux 5.15.0-52-generic #58-Ubuntu SMP x86_64

GCC build options:
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
12.1.0-2ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-12-sZcx2y/gcc-12-12.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-sZcx2y/gcc-12-12.1.0/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu

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

end of thread, other threads:[~2022-11-18  0:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 15:00 [Bug libstdc++/107735] New: Inconsistent error messages for std::array out of bound andrzej at rpi dot pl
2022-11-17 16:31 ` [Bug c++/107735] " redi at gcc dot gnu.org
2022-11-17 22:24 ` pinskia at gcc dot gnu.org
2022-11-18  0:46 ` [Bug c++/107735] Inconsistent error messages for std::array out of bound due to taking the address of one-past-the-end is valid redi at gcc dot gnu.org
2022-11-18  0:49 ` pinskia at gcc dot gnu.org

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).