#This script is designed to run with Understand - CodeCheck use base ("Understand::Codecheck"); use strict; use constant ERR1 => '#include %1 contains one or more non-standard characters'; sub register_tr_text() { my $check = shift; $check->add_tr_text(ERR1); } sub name { return "16-2-4 The ', \", /* or // characters shall not occur in a header file name.";} sub description { return "16-2-4 (Required) The ', \", /* or // characters shall not occur in a header file name.";} sub detailed_description { return <<"END_DESC"
Rationale
It is undefined behaviour if the ', ", /* or // characters are used between < and > delimiters or the
', /* or // characters are used between the " delimiters in a header name preprocessing token.
#include "fi'le.h" // Non-compliantEND_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 check { my $check = shift; my $file = shift; return unless $file->kind->check("file ~unknown ~unresolved"); return unless $file->filerefs("include","file"); my $lexer = $file->lexer(); next unless $lexer; my $lexeme = $lexer->first(); while ($lexeme){ if($lexeme->token eq "Preprocessor" && $lexeme->text eq "include"){ my $string = ""; do { $lexeme = $lexeme->next }while($lexeme && $lexeme->token eq "Whitespace"); $string = $lexeme->ent->type if($lexeme->ent && $lexeme->ent->kind->check("macro")); $string = $lexeme->text if !$string && $lexeme->token eq "String"; next if !$string; if($string =~ /^<.*('|"|\/\*|\/\/).*>$|^".*('|\/\*|\/\/).*"$/){ $check->violation($file,$file,$lexeme->line_begin,$lexeme->column_begin,ERR1,$string); } } }continue{ $lexeme = $lexeme->next; } }