Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 14-7-1 and templates that must be specialized
#1
One of our clients is using code like this:

Code:
template<bool b> SomeClass;

template <> SomeClass<true> {
  void foo();
};
SomeClass<true> s;

We report a 14-7-1 defect, as non-specialized SomeClass is never instantiated.
They're complaining it's a false positive. Could we get a ruling? Arguably the explicit specialization and the non-specialization are different classes, and to be compliant both should be instantiated. On the other hand, this might be a reasonable thing to do if e.g. the goal is to prevent the code from working with <false> (note: I'm only guessing at the goal. The example from the customer doesn't go much further than this)
Do you have any guidance?
Reply
#2
The rule could be made clearer, but the intent was definitely to only cover templates that *are* instantiatable. Therefore, this could be seen as a false positive against a tool as there is no definition of SomeClass.

However, given modern C++ techniques, the presence of templates that are not intended to be instantiated (with or without definitions) makes this kind of rule Undecidable at best, with questionable value.

With this in mind, the rule is under consideration of the next version.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)