From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9549 invoked by alias); 30 Mar 2015 07:24:30 -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 9485 invoked by uid 48); 30 Mar 2015 07:24:23 -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: Mon, 30 Mar 2015 08:18: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: REOPENED 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/msg03358.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398 --- Comment #6 from Mitsuru Kariya --- I also found a strange behavior like below. ============================== sample code ============================== #include constexpr char s1[] = "s1"; constexpr char s2[] = "s2"; bool f(const char* p1, const char* p2) { return p1 == p2; } constexpr auto eq1 = &s1[sizeof(s1)] == &s2[0]; auto eq2 = f(&s1[sizeof(s1)], &s2[0]); int main() { std::cout << static_cast(&s1[sizeof(s1)]) << std::endl; std::cout << static_cast(&s2[0]) << std::endl; std::cout << std::boolalpha << eq1 << ", " << eq2 << std::endl; } ============================== sample code ============================== ============================== output ============================== 0x400bb8 0x400bb8 false, true ============================== output ============================== cf. http://melpon.org/wandbox/permlink/Iu0rFFMgeYqT98fo I think that it should either 1) cause a compilation error at the definition of the eq1 if the result of "&s1[sizeof(s1)] == &s2[0]" is "unspecified". or 2) output "true, true" because both the "&s1[sizeof(s1)]" and "&s2[0]" represent the same address. but I am not sure which behavior is appropriate. (I cannot find an explicit description by which comparison between one past the end pointer and another object's pointer is "unspecified behavior", in the C++ standard.)