From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A68A739960D0; Thu, 17 Nov 2022 15:00:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A68A739960D0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668697200; bh=O9z4JFLyWjJfOlu5pE0hE72iAUjtFA60edcq5y8q+Kc=; h=From:To:Subject:Date:From; b=FCo7YMiE8oxuaNJLYwF7bfBcHOv342e0rvCOCoIrI8ySw18H7meKPNcIfxfDyOinn 9JnKyn4Gh9DgnDXXML0yTk4AsU+F+ATV2rP0YsD+PF0/ogI6ka8pnOZvdhXWe7Z+Zg UvUW/UDq4VBT29/i8+bhISFxU8MYcnx6jgzhDfsU= From: "andrzej at rpi dot pl" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107735] New: Inconsistent error messages for std::array out of bound Date: Thu, 17 Nov 2022 15:00:00 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andrzej at rpi dot pl X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107735 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=3D53919&action=3Dedit Preprocessed file The second and third lines of following code produce different `out of boun= d` 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= =20=20 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=20 constexpr std::array array =3D {1, 2, 3}; constexpr int v1 =3D array[3]; constexpr int v2 =3D array[4]; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Compilation line: `g++-12 a-minimal_example.ii` Compiler output: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ minimal_example.cpp:6:27: error: array subscript value =E2=80=983=E2=80=99 = is outside the bounds of array type =E2=80=98std::__array_traits::_Type=E2=80=99 {= aka =E2=80=98const int [3]=E2=80=99} 6 | constexpr int v1 =3D array[3]; | ^ In file included from minimal_example.cpp:1: minimal_example.cpp:9:27: in =E2=80=98constexpr=E2=80=99 expansion of =E2= =80=98array.std::array::operator[](4)=E2=80=99 /usr/include/c++/12/array:219:25: in =E2=80=98constexpr=E2=80=99 expansio= n of =E2=80=98std::__array_traits::_S_ref(((const std::array*)this)->std::array::_M_elems, __n)=E2=80=99 /usr/include/c++/12/array:61:36: error: array subscript value =E2=80=984=E2= =80=99 is outside the bounds of array type =E2=80=98std::__array_traits::_Type=E2=80= =99 {aka =E2=80=98const int [3]=E2=80=99} 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=3D'Ubuntu 12.1.0-2ubuntu1~22.04' --with-bugurl=3Dfile:///usr/share/doc/gcc-12/README.= Bugs --enable-languages=3Dc,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=3D/usr --with-gcc-major-version-only --program-suffix=3D-12 --program-prefix=3Dx86_64-linux-gnu- --enable-shared --enable-linker-build-= id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --libdir=3D/usr/lib --enable-nls --enable-clocale=3Dgnu --enable-libstdcxx-= debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=3Drelea= se --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-multiarch --disable-werror --enable-cet --with-arch-32=3Di686 --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=3Dgeneric --enable-offload-targets=3Dnvptx-none=3D/build/gcc-12-sZcx2y/gcc-12-12.1.0/= debian/tmp-nvptx/usr,amdgcn-amdhsa=3D/build/gcc-12-sZcx2y/gcc-12-12.1.0/deb= ian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linu= x-gnu=