[cfe-dev] clang c++0x template function declaration error
dgregor at apple.com
Sat Jul 16 22:09:16 PDT 2011
On Jul 16, 2011, at 8:04 PM, Seth Cantrell wrote:
> On Jul 16, 2011, at 2:45 PM, John McCall wrote:
>> On Jul 16, 2011, at 9:31 AM, Seth Cantrell wrote:
>>> Could the diagnostics be improved over
>>>> test.cpp:4:6: note: candidate template ignored: substitution failure
>>>> [with T = Y]
>>>> auto type_constructor( void (T::*f)() ) -> X< T, f >;
>>> Maybe an added note that points at the f in X<T,f> to say that that's why the substitution failed?
>> While I agree that 'substitution failure' by itself is not very helpful, I'm very reluctant to use multiple notes per failed overload candidate, at least for the default console diagnostics. Is there a good way to explain the problem based on the kind of substitution failure?
> Okay, I think not multiplying notes that way is good. Thinking about it more, it seems like this shouldn't even be a note attached to an error because I don't think there's any way the template could ever be instantiated. Instead as soon as clang sees:
>> template <class T>
>> auto type_constructor( void (T::*f)() ) -> X< T, f >;
> it seems like it should pop out an error declaring that the template is invalid (and explaining why by stating that the function's parameter 'f' can't be used as a non-type template parameter in X<T,f>). I'm not exactly sure what the restrictions are on what values can be used as non-type template parameters, but it's obvious that the value has to be available at compile time.
This is certainly something that Clang could detect by looking at the form of the declaration. The compiler is allowed (but not required) to reject this template (since there are no valid instantiations of the template).
As for the more general case... it would be great to give more information about why a particular candidate failed during substitution, perhaps by trapping the diagnostic generated while performing the substitution and adding its text at the end of the "substitution failure" note. We certainly can't have multiple notes, though.
More information about the cfe-dev