Please see the sample codes 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 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 2 ========================== ========================= error message 2 ========================= sample2.cpp:2:15: error: '((& s[0]) == ((& s[0]) + 1u))' is not a constant expression return found == last; ^ ========================= error message 2 ========================= ========================== sample code 3 ========================== constexpr char s1[] = "s1"; constexpr char s2[] = "s2"; constexpr auto eq = (s1 + 0) == (s2 + 1); int main() {} ========================== sample code 3 ========================== ========================= error message 3 ========================= sample3.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 3 ========================= The sample code 1 and 2 are compiled successfully on the 4.9.2, but they cause an error on the head revision. The sample code 3 causes an error on the 4.9.2 and the head revision. These testcases are derived from bug 65398.
I'll take a look.
Created attachment 35214 [details] pr65642.patch Untested patch for example 1 and 3.
(In reply to Marek Polacek from comment #3) > Created attachment 35214 [details] > pr65642.patch > > Untested patch for example 1 and 3. 1 and 2. 3 is different.
Author: mpolacek Date: Thu Apr 2 16:51:27 2015 New Revision: 221843 URL: https://gcc.gnu.org/viewcvs?rev=221843&root=gcc&view=rev Log: PR c++/65642 * constexpr.c (cxx_eval_pointer_plus_expression): Call cxx_eval_constant_expression on the first operand. * g++.dg/cpp0x/constexpr-fold1.C: New test. * g++.dg/cpp0x/constexpr-fold2.C: New test. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-fold1.C trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-fold2.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/constexpr.c trunk/gcc/testsuite/ChangeLog
I think that fixing the third case is going to be harder, and doesn't look like something that should be fixed in cp/constexpr.c. While fold_comparison is able to fold the NE_EXPR here: constexpr char s1[] = "s1"; constexpr char s2[] = "s2"; constexpr auto eq = (s2 + 2) != (s2 + 1); it isn't able to fold it here: constexpr char s1[] = "s1"; constexpr char s2[] = "s2"; constexpr auto eq = (s1 + 2) != (s2 + 1); So not sure what to do here, but in any case, I think it is a GCC 6 material.
GCC 6.1 has been released.
GCC 6.3 is being released, adjusting target milestone.
GCC 6.4 is being released, adjusting target milestone.
Can the bug be marked as resolved?
I think the last example is similar to bug 89074 comment #5.
(In reply to Martin Liška from comment #10) > Can the bug be marked as resolved? At the time you asked, no, because the third example still failed. But it compiles since r12-6382 (PR89074, as Andrew suggested). So now it can be closed as fixed in GCC 12.