https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85746
Bug ID: 85746 Summary: Premature evaluation of __builtin_constant_p? Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org Target Milestone: --- int f(int a,int b){ int c = __builtin_constant_p(a < b); return c; } In C or C++98, __builtin_constant_p is passed to the middle-end for further optimization. In C++11, the front-end produces "c = 0;". That's because C++11 says we should check if the initializer can be constexpr-evaluated, and inside constexpr evaluation we force the early (pessimistic) evaluation of __builtin_constant_p. Maybe we should only evaluate __builtin_constant_p to false when we are committed to a constexpr evaluation, not for tentative ones as in initializers? Or maybe we need different versions of __builtin_constant_p for people who want to use it as if constexpr() and for those who want late optimization?