From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23360 invoked by alias); 31 Mar 2015 16:04:01 -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 Received: (qmail 23290 invoked by uid 48); 31 Mar 2015 16:03:57 -0000 From: "kariya_mitsuru at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization Date: Tue, 31 Mar 2015 16:19:00 -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: 5.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: kariya_mitsuru at hotmail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: 5.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-03/txt/msg03552.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398 --- Comment #13 from Mitsuru Kariya --- Thank you for your quick response. But unfortunately, I found problems like below. ========================== sample code 1 ========================== constexpr char f(const char* s) { return *(s + 1); } constexpr char s[] = "ss"; constexpr auto c = f(&s[0]); int main() {} ========================== sample code 1 ========================== ========================= error message 1 ========================= sample1.cpp:8:21: in constexpr expansion of 'f((& s[0]))' sample1.cpp:8:27: error: '*(s + 1u)' is not a constant expression constexpr auto c = f(&s[0]); ^ ========================= error message 1 ========================= ========================== sample code 2 ========================== constexpr char s1[] = "s1"; constexpr char s2[] = "s2"; constexpr auto eq = (s1 + 0) == (s2 + 1); int main() {} ========================== sample code 2 ========================== ========================= error message 2 ========================= sample2.cpp:4:30: error: '(((const char*)(& s1)) == (((const char*)(& s2)) + 1u))' is not a constant expression constexpr auto eq = (s1 + 0) == (s2 + 1); ^ ========================= error message 2 ========================= ========================== sample code 3 ========================== constexpr bool g(char const* found, char const* last) { return found == last; } constexpr bool f(const char* s) { return g(s, s + 1); } constexpr char s[] = "ss"; constexpr auto b = f(&s[0]); int main() {} ========================== sample code 3 ========================== ========================= error message 3 ========================= sample3.cpp:2:15: error: '((& s[0]) == ((& s[0]) + 1u))' is not a constant expression return found == last; ^ ========================= error message 3 ========================= The sample code 1 is compiled successfully on both the 4.9.2 and the previous revision but it causes an error on the head revision. The sample code 2 causes an error on the 4.9.2, the previous revision and the head revision. The sample code 3 is compiled successfully on the 4.9.2, but it causes an error on both the previous revision and the head revision. (I use a constexpr library and its tests are passed on 4.9.2 but are failed on 5.0.0.)