https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78420
--- Comment #23 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Jason Merrill from comment #22) > Hmm, this seems to work: > > typedef decltype(sizeof(1)) size_t; > > constexpr bool less (const int*a, const int*b) > { > if (__builtin_constant_p (a < b)) > return a < b; > return (size_t)a < (size_t)b; > } > > int ar[3]; > int i; > > constexpr bool l1 = less(&ar[0], &ar[1]); // OK > constexpr bool l2 = less(&ar[0], &i); // error, non-constant I'd fear about jump-threading vs. __builtin_constant_p issues like PR72785 and others, were the optimizers break the __builtin_constant_p argument and the guarded expression appart and something different might be propagated into them or evaluated differently etc. One possibility would be a __builtin_constant_p-like builtin that would fold to false much earlier than the current __builtin_constant_p, e.g. during gimplification. Or use p0595r0 if (constexpr () && a < b) return a < b; or similar builtin if (__builtin_in_constexpr_p () && a < b) return a < b; Again, fold this builtin to true if inside constexpr.c, and to false say in the C++ gimplification langhook.