<div dir="ltr">I'm going to guess it's mostly (3). Checking and trying to constant evaluate every subexpression would be expensive - the systems to do so in Clang have to do a lot of work to properly report diagnostics, to act on the full AST form, etc. It's easier to leave it to the LLVM optimization passes to do the work, when possible.<br><br><div class="gmail_quote"><div dir="ltr">On Wed, Feb 22, 2017 at 1:58 AM Roger Ferrer Ibanez via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br class="gmail_msg">
<br class="gmail_msg">
maybe this is just a silly question. But I wondered why clang is not attempting to fold calls to constexpr functions in non-constant expression contexts.<br class="gmail_msg">
<br class="gmail_msg">
Example:  <a href="https://godbolt.org/g/KBaMjp" rel="noreferrer" class="gmail_msg" target="_blank">https://godbolt.org/g/KBaMjp</a> just compare "one" vs "two" in the IR<br class="gmail_msg">
<br class="gmail_msg">
I understand that clang does not have to do this and I'm not saying it should.<br class="gmail_msg">
<br class="gmail_msg">
But I'd like to know what is the rationale here.<br class="gmail_msg">
- Is it a C++ Standard issue?, i.e. doing that would trigger some side-effects that would be non-compliant.<br class="gmail_msg">
- Is it a "separation of concerns" issue?, i.e. let LLVM optimize these cases and improve if it can't.<br class="gmail_msg">
- Is it a speed issue?, i.e. even if the original AST is preserved for fidelity, computing an associated constant value to it takes time which is precious for some clients.<br class="gmail_msg">
<br class="gmail_msg">
Or maybe it is something else that didn't occur to me.<br class="gmail_msg">
<br class="gmail_msg">
Thank you,<br class="gmail_msg">
Roger<br class="gmail_msg">
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
</blockquote></div></div>