From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 10A3A38356BF; Fri, 10 Jun 2022 14:01:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10A3A38356BF From: "ed at catmur dot uk" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105918] New: Spurious Warray-bounds in std::to_chars Date: Fri, 10 Jun 2022 14:01:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ed at catmur dot uk 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 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Jun 2022 14:01:14 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105918 Bug ID: 105918 Summary: Spurious Warray-bounds in std::to_chars Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ed at catmur dot uk Target Milestone: --- #include template std::to_chars_result toChars(char (& buf)[N], int number) { char temp[N]; std::to_chars_result result =3D std::to_chars(temp, temp + N, number); if (result.ec !=3D std::errc()) return result; char* it =3D temp; char* end =3D result.ptr; std::size_t i =3D 0u; while (i !=3D N && it !=3D end) buf[i++] =3D *it++; if (i !=3D N) buf[i] =3D '\0'; return std::to_chars_result{.ptr =3D buf + (result.ptr - temp), .ec =3D std::errc()}; } #include struct ar { struct V { bool value; } value; std::unique_ptr s; }; void f(...); ar g(); ar evaluate(bool value) { ar res{value}; if (res.value.value) return res; return g(); } #define CHECK(P) f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, evaluate(P), 0, 0, 0, 0, 0= , 0, 0, 0, 0 ); int main() { char s3[3]; auto res3 =3D toChars(s3, 12); CHECK((res3.ec =3D=3D std::errc())); CHECK((s3[0] =3D=3D '1')); CHECK((s3[1] =3D=3D '2')); CHECK((s3[2] =3D=3D '\0')); char s1[1]; auto res1 =3D toChars(s1, 12); CHECK((res1.ec !=3D std::errc())); } Compiled at -O3 -Warray-bounds: In file included from include/c++/12.1.0/charconv:42, from :1: In function 'void std::__detail::__to_chars_10_impl(char*, unsigned int, _T= p) [with _Tp =3D unsigned int]', inlined from 'std::__detail::__integer_to_chars_result_type<_Tp> std::__detail::__to_chars_10(char*, char*, _Tp) [with _Tp =3D unsigned int]= ' at include/c++/12.1.0/charconv:225:35, inlined from 'std::__detail::__integer_to_chars_result_type<_Tp> std::__to_chars_i(char*, char*, _Tp, int) [with _Tp =3D int]' at include/c++/12.1.0/charconv:351:32, inlined from 'std::to_chars_result std::to_chars(char*, char*, int, int= )' at include/c++/12.1.0/charconv:370:1, inlined from 'std::to_chars_result toChars(char (&)[N], int) [with int = N =3D 1]' at :7:48: include/c++/12.1.0/bits/charconv.h:95:22: warning: array subscript 1 is out= side array bounds of 'char [1]' [-Warray-bounds] 95 | __first[1] =3D __digits[__num + 1]; | ~~~~~~~~~~~^~~~~~~~~~~ : In function 'std::to_chars_result toChars(char (&)[N], int) [with= int N =3D 1]': :6:10: note: at offset 1 into object 'temp' of size 1 6 | char temp[N]; | ^~~~ :6:10: note: at offset 2 into object 'temp' of size 1 Compiler returned: 0=