parameter checking in variadic diagnostic messages

"James K. Lowden" <[email protected]>
Newsgroups gmane.comp.gcc.help
Message-ID <[email protected]>
How does one or how might we validate parameters before they're
presented to emit_diagnostic_valist?  Or, not use
emit_diagnostic_valist?  

In the cobol FE, I'm moving all diagnostic message text to a table.
Each element in the table has an enumerated type the defines the
message; it is associated with a -Wname on the command line.  It has a
"kind" (warning, error, ignored) and a dialect.  When the command line
is processed, the "kind" values are adjusted.  When any diagnostic is
indicated, the parser makes call of the form

	cbl_diagnostic(cbl_diag_t, ... )

That function looks up the error and determines its kind.  It extracts
the error text from the table and calls emit_diagnostic_valist.  

It's all very neat and tidy IMO except that the compiler will not warn
me if cbl_diagnostic supplies an incorrect or incomplete list of
parameters to emit_diagnostic_valist.  That's a testing nightmare for
little old me, because there are hundreds of such calls and every one
is on an error branch.  

AFAIK gcc doesn't verify functions that accept a va_list. To avoid
looking foolish, I just tried vprintf(3) with -Wall and -pedantic,
using incorrect parameters, and it compiled just fine.  

I think this is considered outside the scope of "compiler" and is
considered to be the realm of static analysis.  Certainly everything is
known at compile time; the parameter list isn't generated dynamically.
But I suspect va_list is a kind of run-time gadget.  It marks where the
arguments will be at runtime without capturing what they will be. 

ISTM this may be a case for C++11 variadic templates.  But I haven't
used them, and I don't see how a function parameter pack can be
expanded into a set of ordinary arguments.  

I am tempted to use a variadic macro, which solves the problem, well,
not "neatly", but, well, solves the problem.   In my head I hear
Stroustrup telling me the preprocessor is obsolete, yet here we are.  

If it can be done with the compiler we have, please tell me.  If not,
for my own edification I'd like to know what would have to be true for
it to work.  

TIA.  

--jkl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.