Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 14–8–1 and dissimilar overloaded templates
#1
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:
template  void f ( T );  // #1
template  void f ( T*, T ); // #2

template  void f ( 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 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:

Quote: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.
<r>James Widman<br/>
-- <br/>
Gimpel Software<br/>
<URL url="http://gimpel.com">http://gimpel.com</URL></r>
Reply
#2
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++.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)