C and C++


LANG.COMM.CODE : Commented-out Code

Summary

A comment appears to contain a lot of code.

Comment text is considered likely to be code if its proportion of operator characters (!#%^&*()+={}\[]:;<>/) is consistent with that typically seen in C and C++ source code. This heuristic can be thrown off by short comments, so warnings will not be issued for comments that contain only a small number of characters.

The various thresholds involved in this determination are controlled by configuration file parameters:

See the linked individual parameter documentation for full details.

Properties

Class Name Commented-out Code
Significance style
Mnemonic LANG.COMM.CODE
Categories
MisraC2023 MisraC2023:D.4.4 Sections of code should not be "commented out"
Misra2012 Misra2012:D.4.4 Sections of code should not be "commented out"
Misra2004 Misra2004:2.4 Sections of code should not be "commented out"
AUTOSARC++14 AUTOSARC++14:A2-7-2 Sections of code shall not be "commented out".
MisraC++2008 MisraC++2008:2-7-2 Sections of code shall not be "commented out" using C-style comments.
  MisraC++2008:2-7-3 Sections of code should not be "commented out" using C++ comments.
MisraC++2023 MisraC++2023:5.7.2 Sections of code should not be "commented out"
CWE CWE:615 Inclusion of Sensitive Information in Source Code Comments
  CWE:1085 Invokable Control Element with Excessive Volume of Commented-out Code
JSF++ JSF++:127 Code that is not used (commented out) shall be deleted.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Commented-out Code"

Example

int f (int i){
                 /* 'Commented-out Code' warning issued for following comment block */
  
    /* int b;
     * int a = i;
     * a = i++;
     * b = g(a);
     */

    i++;
 
    /* this comment is ordinary text */                  /* does not contain source code */
    return i;
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.