https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87594
Bug ID: 87594 Summary: constexpr rejects-valid code with range-based for-loop Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mpolacek at gcc dot gnu.org Target Milestone: --- Related to PR87567: // { dg-do compile { target c++14 } } constexpr bool always_false() { return false; } int f() { return 1; } constexpr int fn1() { struct empty_range { constexpr int* begin() { return 0; } constexpr int* end() { return 0; } } e; for (auto x : e) f(); return 0; } constexpr int fn2 () { int a[] = { 1, 2, 3 }; for (auto x : a) f(); // { dg-error "call to non-.constexpr. function" } return 0; } constexpr int fn3 () { __extension__ int a[] = { }; for (auto x : a) f(); return 0; } template<typename> constexpr int fn4 () { struct empty_range { constexpr int* begin() { return 0; } constexpr int* end() { return 0; } } e; constexpr int j = ({ for (auto x : e) f(); 1; }); return 0; } template<typename> constexpr int fn5 () { __extension__ int a[] = { }; constexpr int j = ({ for (auto x : a) f(); 1; }); return 0; } void bar () { constexpr int i1 = fn1 (); constexpr int i2 = fn2 (); constexpr int i3 = fn3 (); constexpr int i4 = fn4<int> (); constexpr int i5 = fn5<int> (); }