public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ed at catmur dot uk" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-105918-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105918 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 <charconv> template<int N> std::to_chars_result toChars(char (& buf)[N], int number) { char temp[N]; std::to_chars_result result = std::to_chars(temp, temp + N, number); if (result.ec != std::errc()) return result; char* it = temp; char* end = result.ptr; std::size_t i = 0u; while (i != N && it != end) buf[i++] = *it++; if (i != N) buf[i] = '\0'; return std::to_chars_result{.ptr = buf + (result.ptr - temp), .ec = std::errc()}; } #include <memory> struct ar { struct V { bool value; } value; std::unique_ptr<int> 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 = toChars(s3, 12); CHECK((res3.ec == std::errc())); CHECK((s3[0] == '1')); CHECK((s3[1] == '2')); CHECK((s3[2] == '\0')); char s1[1]; auto res1 = toChars(s1, 12); CHECK((res1.ec != std::errc())); } Compiled at -O3 -Warray-bounds: In file included from include/c++/12.1.0/charconv:42, from <source>:1: In function 'void std::__detail::__to_chars_10_impl(char*, unsigned int, _Tp) [with _Tp = unsigned int]', inlined from 'std::__detail::__integer_to_chars_result_type<_Tp> std::__detail::__to_chars_10(char*, char*, _Tp) [with _Tp = 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 = 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 = 1]' at <source>:7:48: include/c++/12.1.0/bits/charconv.h:95:22: warning: array subscript 1 is outside array bounds of 'char [1]' [-Warray-bounds] 95 | __first[1] = __digits[__num + 1]; | ~~~~~~~~~~~^~~~~~~~~~~ <source>: In function 'std::to_chars_result toChars(char (&)[N], int) [with int N = 1]': <source>:6:10: note: at offset 1 into object 'temp' of size 1 6 | char temp[N]; | ^~~~ <source>:6:10: note: at offset 2 into object 'temp' of size 1 Compiler returned: 0
next reply other threads:[~2022-06-10 14:01 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-06-10 14:01 ed at catmur dot uk [this message] 2022-06-21 5:48 ` [Bug tree-optimization/105918] [12/13 Regression] " pinskia at gcc dot gnu.org 2022-07-08 12:34 ` [Bug tree-optimization/105918] [12/13 Regression] Spurious Warray-bounds in std::to_chars since r12-2132-ga110855667782dac marxin at gcc dot gnu.org 2022-07-25 16:03 ` rguenth at gcc dot gnu.org 2022-11-29 18:14 ` rguenth at gcc dot gnu.org 2023-05-08 12:24 ` [Bug tree-optimization/105918] [12/13/14 " rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-105918-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).