Subject: [boost] dramatically improved template error messages (was: C++11 decltype/SFINAE puzzler)
From: Eric Niebler (eric_at_[hidden])
Date: 2012-08-14 15:25:16
(Andrew, a specific question for you below...)
(Moderators: can you see why this msg from Andrew never reached the list
(which he cc'ed))?
On 8/14/2012 8:39 AM, Andrew Sutton wrote:
>> GCC-4.7 gives a similarly terse error message. This, I think, is what
>> I've been looking for.
> That's neat. Bravo!
I've refined this idea. It now avoids cascading errors by detecting when
a sfinae_error is passed as an argument to another function. (For the
Haskell-ers out there, that makes it like the Either monad.) You can
also get the full backtrace by uncommenting one line of code.
IMO, this is now approaching something of real value. My personal
experience using this with Proto-11 is that it dramatically improves
error messages. I can also easily imagine how this can be used to
implement a very nice concept-checking library for C++11 that
approximates auto-concepts. Andrew, any thoughts on this? You've done
far more work in this space than I have.
I'd also like to know *why* this works, and indeed if it's guaranteed
to. In particular, is it guaranteed that the virtual what() member of
the sfinae_error class is instantiated at the outermost call site and
not elsewhere (thereby eliminating the deep template back-trace)? I
really just stumbled on this technique by accident, and I don't know how
thin the ice is here. Both clang-trunk and gcc-4.7 think it's ok.
(I'd also like to apologize to Paul Fultz for spelling his name wrong in
an earlier message.)
-- Eric Niebler BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk