Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-04-15 03:25:44


Brian McNamara wrote:

> More generally, I would really like a Boost library which lets me
> generate custom error messages portably.
...
> lam2.cpp:94: instantiated from here
> lambda.hpp:1137: no method `boost::fcpp::lambda_impl::
> YouCannotPassTheSameLambdaVarTo_lambda_MoreThanOnce<true>::go'
...
> What I would really love is if there were a boost library which enabled
> me to dispatch messages along the lines of
>
> BOOST_CUSTOM_ERROR( b, msg )
> BOOST_CUSTOM_WARNING( b, msg )

It probably should be a class which can be used like this:

   mpl::apply_if< ...,
             identity<int>,
             COMPILE_TIME_ERROR<Required_property_not_found> > ;

Though I don't have a use case for this yet. If we want insantiation of
COMPILE_TIME_ERROR to generate an error message, then error must be inside
type declaration, since member functions are not instantiated.

So the simplest version can be:

   template<class ErrorMessage>
   class COMPILE_TIME_ERROR {
      typedef typename ErrorMessage::oops type;
   };

   class Life_is_hard {};

Which actually produces *very* nice output:

sa.cpp: In instantiation of `COMPILE_TIME_ERROR<Life_is_hard>':
/home/ghost/Work/boost/boost/mpl/apply_if.hpp:39: instantiated from
`boost::mpl::apply_if<boost::mpl::int_<0>, boost::mpl::identity<int>,
COMPILE_TIME_ERROR<Life_is_hard> >'
sa.cpp:20: instantiated from here
....

Which has "COMPILE_TIME_ERROR" in the very first line (other variants I've
tried mention COMPILE_TIME_ERROR on the second/third/... line).
But if some compiler generates good message only if error is inside function
body we're out of luck. I attach my test if somebody is interested in
trying on other compilers, and in case mailman will strip it, it's also at

   http://zigzag.cs.msu.su:7813/sa.cpp
           
> where in both cases "b" is a compile-time boolean, "msg" is the name of
> a type, and the behavior is
>
> if the boolean is true
> force this compiler to generate a short diagnostic with typename
> "msg" featured prominently
>
> In the long run, there really needs to be language support for
> meta-programs to generate legible diagnostics, but in the meantime, I
> would love a stopgap solution along the lines above. I think it would
> "only" involve the work of finding the best "trick" for each compiler
> brand/version. Perhaps a little concerted effort would discover one
> trick which worked well across many compilers.

Possibly. Useing an non-existent method is likely to work.

> Is there interest in this?

Sure. In particular, I'd like to see a number of static assertions added to
BGL, to make error messages less confusing.

- Volodya




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk