Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3691

Partial specialization syntax should not be used for function templates

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Hide
      Remove the template arguments from this function template.
      Show
      Remove the template arguments from this function template.
    • Highlighting:
      Hide
      template<typename T>
      void fun<T>(T p) {
      //   ^^^^^^    the template-id
      
      Show
      template<typename T> void fun<T>(T p) { // ^^^^^^ the template-id
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way, MISRA C++ 2008 recommended
    • Covered Languages:
      C, C++
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      30min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      Class templates can be explicitly or partially specialized. But according to the C++ standard, function templates cannot be partially specialized. Under certain conditions, the Microsoft® compiler will silently ignore the confusing application of partial specialization syntax to a function, but other compilers will raise an error for it and fail compilation.

      Noncompliant Code Example

      template<typename T>
      void fun(T p);
      
      template<typename T>
      void fun<T>(T p) { // Noncompliant
        // ...
      }
      

      Compliant Solution

      template<typename T>
      void fun(T p);
      
      template<typename T>
      void fun(T p) {
        // ...
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              alban.auzeill Alban Auzeill
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: