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:
ASSERT_STRM(Ty == STy, "Expected " << Ty << " but got " << STy->getElementType(0));
This would transform to:
if (!(Ty == STy))
AssertionFailureStream(FILE, LINE) <<
"Expected " << Ty << " but got " << STy->getElementType(0);
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.)
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.
The actual definition of the macro would be something like this:
#define ASSERT_STRM(cond, args)
if (!(cond)) AssertionFailureStream(FILE, LINE) << args
Note that there’s no trailing semicolon, as this is supplied at the point where the macro is invoked.
What do you think?