public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107735] Inconsistent error messages for std::array out of bound Date: Thu, 17 Nov 2022 22:24:07 +0000 [thread overview] Message-ID: <bug-107735-4-nfxCzo79AX@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-107735-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107735 --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- I wonder if this is because doing constexpr const int *v1 = &array[3]; is valid and well defined. Even clang gives two different error messages: <source>:3:21: error: constexpr variable 'v1' must be initialized by a constant expression constexpr const int v1 = array[3]; ^ ~~~~~~~~ <source>:3:26: note: read of dereferenced one-past-the-end pointer is not allowed in a constant expression constexpr const int v1 = array[3]; ^ <source>:4:15: error: constexpr variable 'v2' must be initialized by a constant expression constexpr int v2 = array[4]; ^ ~~~~~~~~ /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.0/../../../../include/c++/13.0.0/array:213:9: note: cannot refer to element 4 of array of 3 elements in a constant expression return _M_elems[__n]; ^ <source>:4:20: note: in call to '&array->operator[](4)' constexpr int v2 = array[4]; ^ ---- CUT ---- I do think clang's note of one-past-the-end gives more of a hint of why the error message is different though. And I do think GCC could add that note.
next prev parent reply other threads:[~2022-11-17 22:24 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-17 15:00 [Bug libstdc++/107735] New: " 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 [this message] 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
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-107735-4-nfxCzo79AX@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).