#This script is designed to run with Understand - CodeCheck #Rule 8.5 There shall be no definitions of objects or functions in a header file. use base qw(Understand::Codecheck); use strict; use constant ERR1 => 'Violation: "%1" defined in header file.'; sub register_tr_text { my $check = shift; $check->add_tr_text(ERR1); } sub name { '8.5 No definitions of objects or functions in a header file' } sub description { '8.5 (Required) There shall be no definitions of objects or functions in a header file.' } sub detailed_description { <<'END_DESC' Header files should be used to declare objects, functions, typedefs, and macros. Header files shall not contain or produce definitions of objects or functions (or fragment of functions or objects) that occupy storage. This makes it clear that only C files contain executable source code and that header files only contain declarations. A “header file” is defined as any file that is included via the #include directive, regardless of name or suffix. END_DESC } sub test_language { my $language = shift; return $language eq 'C++'; } sub test_entity { 1 } sub test_global { 0 } sub define_options { my $check = shift; } sub check { my $check = shift; my $file = shift; return unless $file->kind->check('c header file ~unknown'); my @refsDefined = $file->filerefs('define', 'function, object', 0); foreach my $ref (@refsDefined) { next if $ref->ent->kind->check('member object ~static'); $check->violation($ref->ent, $file, $ref->line, $ref->column, ERR1, $ref->ent->name); } return; }