#This script is designed to run with Understand - CodeCheck #Rule 2-7-1 The character sequence /* shall not be used within a C-style comment. use base qw(Understand::Codecheck); use strict; use constant ERR1 => 'Violation: /* found inside C-style comment:' . "\n/*%1*/"; sub register_tr_text { my $check = shift; $check->add_tr_text(ERR1); } sub name { '2-7-1 The character sequence /* shall not be used within a C-style comment' } sub description { '2-7-1 (Required) The character sequence /* shall not be used within a C-style comment.' } sub detailed_description { <<'END_DESC'

Rationale
C++ does not support the nesting of C-style comments even though some compilers support this as a non-portable language extension. A comment beginning with /* continues until the first */ is encountered. Any /* occurring inside a comment is a violation of this rule.

END_DESC } sub test_language { my $language = shift; return $language eq 'C++'; } sub test_entity { 1 } sub test_global { 0 } sub define_options { } sub check { my $check = shift; my $file = shift; return unless $file->kind->check('file'); my $lexer = $file->lexer(0); my @lexemes = $lexer->lexemes if $lexer; foreach my $lexeme (@lexemes){ if ($lexeme->token eq 'Comment' && $lexeme->text =~ m! ^ /\* .* /\* !sx) { $check->violation(0, $file, $lexeme->line_begin, $lexeme->column_begin, ERR1, $lexeme->text); } } return; }