<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><span class="vcard"><a class="email" href="mailto:richard-llvm@metafoo.co.uk" title="Richard Smith <richard-llvm@metafoo.co.uk>"> <span class="fn">Richard Smith</span></a>
</span> changed
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - constexpr fibonacci is not computed at compile time"
href="https://bugs.llvm.org/show_bug.cgi?id=39109">bug 39109</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>NEW
</td>
<td>RESOLVED
</td>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>---
</td>
<td>INVALID
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - constexpr fibonacci is not computed at compile time"
href="https://bugs.llvm.org/show_bug.cgi?id=39109#c2">Comment # 2</a>
on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - constexpr fibonacci is not computed at compile time"
href="https://bugs.llvm.org/show_bug.cgi?id=39109">bug 39109</a>
from <span class="vcard"><a class="email" href="mailto:richard-llvm@metafoo.co.uk" title="Richard Smith <richard-llvm@metafoo.co.uk>"> <span class="fn">Richard Smith</span></a>
</span></b>
<pre>This is not a bug; arbitrary calls to constexpr functions aren't required (and
shouldn't in general be expected) to be evaluated to constants.
If you want to ensure that a value is computed at compile time, there are
plenty of ways to request that (eg, use it to initialize a constexpr variable
or an enumerator, pass it as a template argument, use it as an array bound,
[since C++20] use a consteval function, ...). Use in a return statement is not
such a context.
Since C++20, the initializer of a local const variable of integer or unscoped
enumeration type joins the list (see <a href="http://eel.is/c++draft/expr.const#14.5">http://eel.is/c++draft/expr.const#14.5</a>),
which is why main2 now returns a constant.
I don't think we have any intent to do anything about this. Whether the call to
fib(7) in main is reduced to a constant or not is something we leave up to the
optimizer. We don't convey the fact that the function is declared 'constexpr'
as a stronger hint to optimize it.
(I think it would be entirely reasonable for the optimizer to attempt symbolic
evaluation of function calls to see it can reduce them to a small amount of
straight-line code or to a constant. But I don't think we have such an
optimization pass just yet.)</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>