The C++ front-end uses a call-back mechanism to allow functions to print out reasonable strings for types and functions without putting extra logic in the functions where errors are found. The interface is through the cp_error
function (or cp_warning
, etc.). The syntax is exactly like that of error
, except that a few more conversions are supported:
%C indicates a value of `enum tree_code'.
%D indicates a *_DECL node.
%E indicates a *_EXPR node.
%L indicates a value of `enum languages'.
%P indicates the name of a parameter (i.e. "this", "1", "2", ...)
%T indicates a *_TYPE node.
%O indicates the name of an operator (MODIFY_EXPR -> "operator =").
There is some overlap between these; for instance, any of the node options can be used for printing an identifier (though only %D
tries to decipher function names).
For a more verbose message (class foo
as opposed to just foo
, including the return type for functions), use %#c
. To have the line number on the error message indicate the line of the DECL, use cp_error_at
and its ilk; to indicate which argument you want, use %+D
, or it will default to the first.