Boost logo

Boost Users :

Subject: Re: [Boost-users] [format] How to trigger compile-time error for mismatched arguments
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2008-11-11 03:32:58


2008/11/11 Jeffrey Chang <jeffrey8chang_at_[hidden]>

> Hi,
>
> I'm using boost::format library, and this may be obvious to those
> experienced users: is there any way to detect the mismatch of number of
> expected arguments in a
> boost::format object? Both of the following statements throw out runtime
> exceptions (which is correct):
> std::cout << boost::format ("%s %s") % "Hello";
> std::cout << boost::format ("%s") % "Hello" % "world";
>
> It'd be great if this type of parameter-mismatch error can be caught at
> compile-time, instead of run-time. We use boost::format library extensively
> for logging, and inevitably there're human errors like this mismatched
> number of arguments. IMHO, this kind of error should have been detected by
> compiler at build time, s.t. the developer won't be embarrassed by QA or
> customers at run-time.
>

There is no way to do it in C++. Even gcc's __attribute__(format_arg) won't
help, because boost::format does not accept ellipsis as an argument (and it
also support format that is different from printf's).

Roman Perepelitsa.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net