So I went ahead and implemented this in my own frontend - I've been using it for both assertions and conditional debug statements. I like it quite a bit, and like you say, it compiles down to nothing in non-debug builds.<br>

<br><div><div class="gmail_quote">On Wed, Jul 27, 2011 at 4:00 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im"><div class="gmail_quote">On Wed, Jul 27, 2011 at 3:31 PM, Talin <span dir="ltr"><<a href="mailto:viridia@gmail.com" target="_blank">viridia@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div>Can you explain how it avoids evaluating the arguments in the false case? I looked at the code but it's pretty complex.</div><div><div></div></div></blockquote></div><div><br></div></div><div>Essentially it expands to something like:</div>


<br><div>!(Ty == STy) ? (void)0 : Voidifier() & llvm::dbgs() << ...</div><div><br></div><div>where you have something vaguely along the lines of</div><div><br></div><div>struct Voidifier {</div><div>  void operator&(raw_ostream &);</div>


<div>};</div><div><br></div><div>The conditional expression ensures that the side-effects of the LHS and RHS are contained, while allowing the convenient syntax. The voidifier hack is just for types, there are other simple ways to phrase it that boil down to the same construct. You could also implement it in LLVM as:</div>


<div><br></div><div>if (!(Ty == STy)) {} else llvm::dbgs()</div><div><br></div><div>which works as long as its not used as the lone statement in an unbraced else statement.</div><div><br></div><div>The existing implementations are much more complex in order to support various different constructs. Something like the above would likely serve LLVM's needs. Again, I'm happy to provide a very minimal implementation for consideration if there is interest, I'm just not sure there is interest.</div>


</blockquote></div><br><br clear="all"><br>-- <br>-- Talin<br>
</div>