MISRA Discussion Forums

Full Version: Rule 14-7-1 and templates that must be specialized
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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.