#This script is designed to run with Understand - CodeCheck use base ("Understand::Codecheck"); use strict; use constant ERR1 => 'Comment appears to contain code'; our @keywords = qw(double not_eq throw and_eq dynamic_cast operator true asm try auto enum or_eq typedef bitand explicit private typeid bitor extern protected typename bool false public union float register unsigned case reinterpret-cast using catch friend virtual char goto short void class signed volatile compl inline sizeof wchar_t const int static const-cast long static_cast xor continue mutable struct xor_eq default namespace switch delete new template); our @strongKeywordsRegExp = ('for\s*\(' , 'while\s*\(' , 'if\s*\('); our @preProc = ("#include", "#define", "#endif","#ifndef", "#ifdef"); our @strongLineEnds = (";","{"); our @maybeLineEnds = (")"); our $multiRatio = .4; sub register_tr_text() { my $check = shift; $check->add_tr_text(ERR1); } sub name { return "2-7-2 Sections of code should not be \"commented out\" using C-style comments";} sub description { return "2-7-2 (Required) Sections of code should not be \"commented out\" using C-style comments.";} sub detailed_description { return <<"END_DESC"
Rationale
Using C-style start and end comment markers for this purpose is dangerous because C-style
comments do not support nesting, and any comments already existing in the section of code would
change the effect.
Additionally, comments should only be used to explain aspects of the code that may not be clear from the source code itself. Code that is commented-out may become out of date, which may lead to confusion when maintaining the code.
A more appropriate method of recording the history of changes in source code (e.g. a Source Control System) should be used instead of commenting-out.
Examplevoid fn ( int32_t i ) { /* ++i; /* We want to increment "i" */ */ for ( int32_t j = 0 ; j != i ; ++j ) { } }
See Also
Rule 2-7-1, Rule 2-7-3