[cfe-dev] clang c++0x template function declaration error

John McCall rjmccall at apple.com
Sat Jul 16 11:45:45 PDT 2011


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?

> Here's an example of a similar mistake:
> 
>> #include <functional>
>> 
>> template<typename T>
>> void get(T const &t,size_t N) {
>>    std::get<N>(t);
>> }
>> 
>> int main () {
>>    get(std::make_tuple(1,'a',1.2),2);
>> }
> 
> When compiling this the diagnostics include several notes like the following
> 
>> /usr/include/c++/v1/__tuple:104:1: note: candidate template ignored: invalid explicitly-specified
>>      argument for template parameter '_Ip'
>> get(array<_Tp, _Size>&) _NOEXCEPT;
> 
> "invalid explicitly-specified argument for template parameter" is a little better but it'd be nice to see something pointing directly at the 'N' in std::get<N>(t) saying it's not legal to use arguments as template parameters. Would this be hard to add? Maybe I can give it a try.

Again, we'd rather not introduce extra notes, but it would be fine to just specialize this note for common problems.  For example, here you could say:
  note: candidate template ignored: explicit argument for template parameter '_lp' is not a type
or maybe even
  note: candidate template ignored: explicit argument 'N' for template parameter '_lp' is not a type
where N is a string derived from pretty-printing the argument expression.

John.



More information about the cfe-dev mailing list