#This script is designed to run with Understand - CodeCheck #Robert Gempeler - 7/19/2010 use base ("Understand::Codecheck"); use strict; use constant ERR1 => 'Use of "errno" statement.'; sub register_tr_text() { my $check = shift; $check->add_tr_text(ERR1); } sub name { return "19-3-1 The error indicator \"errno\" shall not be used.";} sub description { return "19-3-1 (Required) The error indicator \"errno\" shall not be used.";} sub detailed_description { return <<"END_DESC" <p><b>Rationale</b><br> <b>errno</b> is a facility of C++ which should in theory be useful, but which in practice is poorly defined by ISO/IEC 14882:2003 [1]. A non-zero value may or may not indicate that a problem has occurred; therefore errno shall not be used.</p> <p>Even for those functions for which the behaviour of errno is well defined, it is preferable to check the values of inputs before calling the function rather than relying on using errno to trap errors.</p> END_DESC } sub test_language { my $language = shift; return $language =~ /C\+\+/; #Handles C and C++ } sub test_entity { return 1;} sub test_global { return 0;} sub define_options{} sub check { my $check = shift; my $file = shift; return unless $file->kind->check("file ~unknown ~unresolved"); my @refs = $file->filerefs("use","object, macro",0); foreach my $ref (@refs){ if ($ref->ent->name =~ /^errno$/){ $check->violation($ref->ent(),$file,$ref->line(),$ref->column(),ERR1); } } }