Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 6.7.2 variable templates
#1
Is the following considered to be compliant:

Code:
template <typename T>
T var = 42;


By itself it seems not to be in the spirit of the rule since there's no "const" in the declaration.  But what if the only instantiation is something like:

Code:
int foo() { return var<const int>; }

Thank you.
Reply
#2
In the introduction to the rules, there's the requirement:

"3.7.3 Templates
Unless otherwise stated, the guidelines shall only be applied to fully instantiated templates"

For a template variable, each instantiation has to be considered separately. So your example with <const int> is compliant, but if it were replaced by <int> it would be non-compliant
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)