#This script is designed to run with Understand - CodeCheck #Robert Gempeler - 7/19/2010 use base ("Understand::Codecheck"); use strict; use constant ERR1 => 'Invalid use of "offsetof" macro.'; sub register_tr_text() { my $check = shift; $check->add_tr_text(ERR1); } sub name { return "20.6 The macro \"offsetof\", in library , shall not be used";} sub description { return "20.6 (Required) The macro \"offsetof\", in library , shall not be used.";} sub detailed_description { return <<"END_DESC" Use of this macro can lead to undefned behaviour when the types of the operands are incompatible or when bit felds are used. 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"); my @refs = $file->filerefs("call","function, macro",0); foreach my $ref (@refs){ if ($ref->ent->name =~ /^offsetof$/){ $check->violation($ref->ent(),$file,$ref->line(),$ref->column(),ERR1); } } }