[Bug c++/85746] New: Premature evaluation of __builtin_constant_p?
glisse at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri May 11 07:53:00 GMT 2018
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?
More information about the Gcc-bugs
mailing list