title: Static function template and MISRA C++
body: <p>The following function template with specializations should be used within the same <code>.cpp</code> file only, so I’d like to make it <code>static</code>. The following code compiles (without warnings) using both MS Visual C++ 2008 and GCC 4.8.1 and works as intended. (Adding <code>static</code> to the beginning of lines 5 and 11 would cause GCC to issue an error but not MSVC.)</p>
  
  <pre><code> 1  template &lt;class T&gt;
   2  static bool foo(const T param);
   3
   4  template &lt;&gt;
   5  bool foo&lt;int&gt;(const int param)
   6  {
   7      return doSomethingWithInt(param);
   8  }
   9
  10  template &lt;&gt;
  11  bool foo&lt;bool&gt;(const bool param)
  12  {
  13      return doSomethingWithBool(param);
  14  }
  </code></pre>
  
  <p>However, MISRA C++ checker complains:</p>
  
  <ul>
  <li>(MISRA2008.3-3-2) Apply the static keyword to declaration of 'foo' (1)</li>
  <li>(MISRA2008.3-3-2) Apply the static keyword to declaration of 'foo' (5)</li>
  <li>(MISRA2008.2-10-5-b) Identifier 'foo' is being reused (5)</li>
  <li>(MISRA2008.3-3-2) Apply the static keyword to declaration of 'foo' (11)</li>
  <li>(MISRA2008.2-10-5-b) Identifier 'foo' is being reused (11)</li>
  </ul>
  
  <p>I tried to find out what’s wrong and found a hint in a <a href="https://stackoverflow.com/a/17662745/711006">C++ standard quote</a>:</p>
  
  <blockquote>
    <p>For a function call that depends on a template parameter, if the
    function name is an unqualified-id but not a template-id, the
    candidate functions are found using the usual lookup rules (3.4.1,
    3.4.2) except that:</p>
    
    <ul>
    <li>For the part of the lookup using unqualified name lookup (3.4.1), only
    function declarations with <strong>external linkage</strong> from the template
    definition context are found.</li>
    </ul>
  </blockquote>
  
  <p>Does it mean that the compilers discard the <code>static</code> specification and there is no way to actually make static function templates in C++03?</p>