The assertions in LLVM would be a lot more useful if they could print out not only the source code of the expression that failed, but also print the values of the various arguments. To that end, I have an idea for an improved assert macro which would use raw_ostream. It would look something like this:<div>

<br></div><div><font class="Apple-style-span" face="'courier new', monospace">   ASSERT_STRM(Ty == STy, "Expected " << Ty << " but got " << STy->getElementType(0));<br clear="all">

</font><br></div><div>This would transform to:</div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">   if (!(Ty == STy))</font></div><div><font class="Apple-style-span" face="'courier new', monospace">     AssertionFailureStream(__FILE__, __LINE__) <<</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">       <meta charset="utf-8">"Expected " << Ty << " but got " << STy->getElementType(0);</font></div><meta charset="utf-8"><div>

<br></div><div>The AssertionFailureStream is a subtype of raw_ostream whose destructor calls abort() after printing the contents of the stream to stderr. (I use a similar technique in my frontend.)</div><div><br></div><div>

As you can see, this ought to work with any argument type that can work with raw_ostream. And it shouldn't cost anything if the assert doesn't fail.</div><div><br></div><div>The actual definition of the macro would be something like this:</div>

<div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">  #define ASSERT_STRM(cond, args) \</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    if (!(cond)) AssertionFailureStream(__FILE__, __LINE__) << args</font></div>

<div><br></div><div>Note that there's no trailing semicolon, as this is supplied at the point where the macro is invoked.</div><div><br></div><div>What do you think?</div><div><br></div><div>-- <br>-- Talin<br>
</div>