#This script is designed to run with Understand - CodeCheck use base qw(Understand::Codecheck); use strict; use Codecheck::Libraries::InfoSiftr qw(getFunctionParams); use constant ERR1 => 'Violation: function %2"%1" has no parameters, and is missing explicit "void" keyword.'; sub register_tr_text { my $check = shift; $check->add_tr_text(ERR1); } sub name { '16.5 Functions with no parameters need explicit void keyword' } sub description { '16.5 (Required) Functions with no parameters shall be declared and defined with the parameter list void.' } sub detailed_description { <<'END_DESC' Functions shall be declared with a return type (see Rule 8.2), that type being void if the function does not return any data. Similarly, if the function has no parameters, the parameter list shall be declared as void. Thus for example, a function, myfunc, which neither takes parameters nor returns a value would be declared as:
    void myfunc ( void );
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; $check->option->checkbox("voidNoParams","Ignore Constructors and Deconstructors",0); } sub check { my $check = shift; my $file = shift; return unless $file->kind->check('file'); my $lexer = $file->lexer(0); foreach my $ref ($file->filerefs('define, declare', 'function', 0)) { my @params = getFunctionParams($ref, $lexer); my $refKind = ''; if ($ref->kind->check('define')) { $refKind = 'definition '; } elsif ($ref->kind->check('declare')) { $refKind = 'declaration '; } unless (@params) { next if($ref->ent->longname =~ /(.*)::~?$1/ && $check->option->lookup("voidNoParams")); $check->violation($ref->ent, $ref->file, $ref->line, $ref->column, ERR1, $ref->ent->longname, $refKind); } } return; }