[Bug tree-optimization/95769] Constant expression in inline function not optimized

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jun 19 15:50:44 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95769

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to John Simon from comment #2)
> (In reply to Jakub Jelinek from comment #1)
> > If you want to ensure a function is evaluated at compile time, it needs to
> > be either C++20 consteval, or you need to evaluate it in constant expression
> > context, e.g. constexpr auto x = expensive_function(10000);
> 
> in this case, doing that will make the `other_function` consteval too, so I
> can't call it with non-constant values.

So you can't make it consteval then, but you can still assign it into const
variable (or even constinit in C++20 to abort compilation if not evaluated into
constant).  Without that, the constexpr means nothing, the compiler might or
might not evaluate it at compile time.


More information about the Gcc-bugs mailing list