https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
Mitsuru Kariya <kariya_mitsuru at hotmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|GCC rejects valid constant |[C++11] GCC rejects valid |expression |constant expression --- Comment #1 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> --- 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.