Page 1 of 1

Rule 14–8–1 and dissimilar overloaded templates

Posted: Fri Jul 04, 2008 12:15 am
by James Widman
Hi all,

I suspect that the net cast by rule 14–8–1 is too wide. For example, I don't think it's helpful to label the following as "non-compliant":

Code: Select all

template <typename T> void f ( T );  // #1
template <typename T> void f ( T*, T ); // #2

template <> void f<int32_t*> ( int32_t* ); // non-compliant with 14–8–1
In this case, the specialization of #1 cannot get you into trouble.

In the actual example given for 14–8–1, it is helpful to claim that the specialization is suspect because there is another template that would have been a better match if only the explicit template argument list <int32_t*> had not been given, and a user (especially someone writing a call to the template) may not have an understanding of the type deduction rules sufficient to know which template would be selected when there are multiple matches and only one match is selected by partial ordering.

But who, without the assistance of medication, would not just assume that #1 (in the example above) is being specialized in the explicit-specialization? Likewise, who, in the absence of default arguments and in the absence of any other overload, would not just assume that #1 would be called when the call expression contains only one argument?

I recommend changing the wording of the rule to:
An overloaded function template shall not be explicitly
specialized if, in the absence of an explicit
template-argument-list, at least one template other than
the selected template would succeed at type deduction against
the function type given by the explicit specialization.

Re: Rule 14–8–1 and dissimilar overloaded templates

Posted: Wed Oct 07, 2015 9:54 am
by misra cpp
It is agreed that the rule currently covers cases that are not ambiguous. This rule will be reviewed for the next revision of MISRA C++.