[LLVMdev] Improving cast<> failure messages.

Sean Hunt scshunt at csclub.uwaterloo.ca
Tue Jun 21 19:54:43 PDT 2011


Would anyone object to an attempt to improve cast<> error messages by 
outputting the expected type and the type received?

The interface I'm thinking of is to use ADL to do visitor-style lookup, 
so we don't need to change every client. In particular, for clients in 
clang, we can just create these functions implicitly from our 
TableGen-generated files. I'm not sure about clients in LLVM since I 
don't do much work there.

This would have to introduce a dependency in llvm/Support/Casting.h on 
some library for string concatenation; preferably <string> but a 
lower-level interface could be used it someone objects (or it could be 
done manually, but that seems horrible).

An example of what this would be like is:

// Before cast<> in llvm/Support/Casting.h
const char *DebugTypeName(void*) {
}

// In the header for the type at some reasonable point before cast<> is
// instatiated for that type
const char *DebugTypeName(Foo*) {
   return "Foo";
}

The pointer is only for ADL purposes and will always be 0.

Sean



More information about the llvm-dev mailing list