From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26091 invoked by alias); 6 May 2011 11:05:06 -0000 Received: (qmail 26081 invoked by uid 22791); 6 May 2011 11:05:05 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 06 May 2011 11:04:52 +0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/48911] [C++0x] Error for valid array subscript X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Fri, 06 May 2011 11:05:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg00554.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48911 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #2 from Jakub Jelinek 2011-05-06 11:00:19 UTC --- Better testcase: // PR c++/48911 // { dg-do compile } // { dg-options "-std=c++0x" } struct A { constexpr A () : a (6) {} int a; }; int main () { constexpr int a[1] = { 0 }; constexpr int i = a[0]; constexpr int b[1] = { }; constexpr int j = b[0]; constexpr char c[2] = "a"; constexpr char k = c[1]; constexpr char d[2] = ""; constexpr char l = d[1]; constexpr wchar_t e[2] = L"a"; constexpr wchar_t m = e[1]; constexpr wchar_t f[2] = L""; constexpr wchar_t n = f[1]; constexpr A g[2] = { A () }; constexpr A o = g[0]; constexpr A p = g[1]; } which covers also the case where ary is not CONSTRUCTOR, but STRING_CST. I think we want to to the len check as done right now, but if index is above len, we shouldn't error or set non-constant unconditionally, instead we should check domain of TREE_TYPE (oldary). If it is within the range, we want to return zero of the appropriate type for PODs, not sure what exactly for constexpr non-PODs.