From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4A83C3853D41; Thu, 17 Nov 2022 22:24:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A83C3853D41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668723848; bh=XVnAxKrnJUcqrv7nprlUDg0m+JVLQ+8K5ilaBkd1wuw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZTQVARZFQXRcMzNP3IofZOZ8dQQA9rDA2H70pcb8Vh97ad1P+JoazmbzYdpONqww+ L3swAelDOIGDxH7NBrvBk3fBDh6gYUgEd0jCseWUwhC+SKnHSqhUEmEY2mr0AUY8s3 RHBMKoqINrl+xxQg6YHOZsN4CpHbP/ET/OmNB9Mw= From: "pinskia at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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 --- Comment #2 from Andrew Pinski --- I wonder if this is because doing=20 constexpr const int *v1 =3D &array[3]; is valid and well defined. Even clang gives two different error messages: :3:21: error: constexpr variable 'v1' must be initialized by a cons= tant expression constexpr const int v1 =3D array[3]; ^ ~~~~~~~~ :3:26: note: read of dereferenced one-past-the-end pointer is not allowed in a constant expression constexpr const int v1 =3D array[3]; ^ :4:15: error: constexpr variable 'v2' must be initialized by a cons= tant expression constexpr int v2 =3D 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 expres= sion return _M_elems[__n]; ^ :4:20: note: in call to '&array->operator[](4)' constexpr int v2 =3D 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.=