#This script is designed to run with Understand - CodeCheck use base ("Understand::Codecheck"); use strict; use constant ERR1 => 'Static Identifier \'%1\' reused'; sub register_tr_text() { my $check = shift; $check->add_tr_text(ERR1); } sub name { return "2-10-5 The identifer name of a non-member object or function with static storage duration should not be reused";} sub description { return "2-10-5 (Advisory) The identifer name of a non-member object or function with static storage duration should not be reused.";} sub detailed_description { return <<"END_DESC"
Rationale
Regardless of scope, no identifer with static storage duration should be re-used across any source
files in the project. This includes objects or functions with external linkage and any objects or
functions with the static storage class specifer.
While the compiler can understand this and is in no way confused, the possibility exists for the
user to incorrectly associate unrelated variables with the same name.
namespace NS1 { static int32_t global = 0; } namespace NS2 { void fn ( ) { int32_t global; // Non-compliant } }END_DESC } sub test_language { my $language = shift; return $language =~ /C\+\+/; #Handles C and C++ } sub test_entity { return 0;} sub test_global { return 1;} sub define_options{} sub check { my $check = shift; my @statics = map{$_->name;}$check->db->ents("static function ~member, static object ~member"); my @notStatics = $check->db->ents("function ~static, object ~static"); foreach my $ent (@notStatics){ if($ent->name ~~ @statics){ my $ref= $ent->ref("define, declare"); $ref = $ent->ref unless $ref; $check->violation($ent,$ref->file,$ref->line,$ref->column,ERR1,$ent->name); } } }