Douglas Gregor | 9 Jun 20:26 2009
Picon

Re: Feature Idea: Error Message Replacing

Hi Sebastian,

On Jun 6, 2009, at 5:50 AM, Sebastian Redl wrote:
> This is a feature idea I just came up with. I have no concrete plans  
> to
> implement this, but I thought I'd post it to the list to see if others
> like it as well, and to preserve it for future reference.
>
> I'm currently working on a Boost library, and in the compile errors  
> this
> shows up:
>
> error: invalid use of incomplete type ‘struct
> boost::property_tree::path_of<boost::any>’
>
> Because I've written this library, I know that this error really  
> means,
> "You haven't specialized the path_of struct for that template argument
> you're trying to use, but this is a prerequisite." If I were a user of
> the library, I'd have no clue.
> I think there should be a way for the library author to communicate  
> this
> knowledge to the user.

What do you need to do that static_assert doesn't already do?

> I'm imagining something like this:
>
> --- File: boost/property_tree/ptree.hpp (the library's main include)  
> ---
(Continue reading)

Sebastian Redl | 10 Jun 18:53 2009
Picon

Re: Feature Idea: Error Message Replacing

Douglas Gregor wrote:
> Hi Sebastian,
>
> On Jun 6, 2009, at 5:50 AM, Sebastian Redl wrote:
>> Because I've written this library, I know that this error really means,
>> "You haven't specialized the path_of struct for that template argument
>> you're trying to use, but this is a prerequisite." If I were a user of
>> the library, I'd have no clue.
>> I think there should be a way for the library author to communicate this
>> knowledge to the user.
>
> What do you need to do that static_assert doesn't already do?
I want to catch and explain arbitrary misuses of the library, beyond
those detectable by the type system. But I admit that static_assert +
concepts cover 95% of the use cases, so implementing this is probably
not worth it.
>> --- File: boost/property_tree/property_tree.en.ec (pseudo-syntax) ---
>> match "invalid use of incomplete type 'struct
>> boost::property_tree::path_of<{T}>'"
>> replacement "you need to specialize 'boost::property_tree::path_of' for
>> '$T' in order to use it as a property tree key"
>
> Isn't this going to be brittle, since the wording of error messages
> might change from one Clang release to another?
Yes. Part of working this out properly would be to devise a way of
making it less brittle.
>
>> Then, when I do
>>
>> boost::basic_ptree<boost::any, int> pt;
(Continue reading)

Douglas Gregor | 10 Jun 23:28 2009
Picon

Re: Feature Idea: Error Message Replacing


>> We could do the same kind of thing through an extension
>> to static_assert:
>>
>>  template<typename T>
>>  struct path_of {
>>    static_assert(always_false<T>::value, "you need to specialize
>> 'boost::property_tree::path_of' for %0 in order to use it as a
>> property tree key", T);
>>  };
>>
>> A couple years back, I prototyped something like this for GCC, using
>> some gross hacks in the G++ front end and a poor approximation of
>> static_assert. The results looked promising, because the custom
>> diagnostic can give much better information than the generic error
>> message, especially if it can refer to your own instantiation.
> This is awesome. We should totally forget about my proposal and
> implement this instead.

:)

   - Doug

Gmane