checksrc: ensure using ifdef/ifndef when possible, fix fallouts

Follow-up to 89771d19d5 #18018

Closes #20065
This commit is contained in:
Viktor Szakats 2025-12-21 15:45:53 +01:00
parent e8415a8296
commit 4ad87f2cb8
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
9 changed files with 30 additions and 11 deletions

View file

@ -162,6 +162,7 @@ my %warnings = (
'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
'FIXME' => 'FIXME or TODO comment',
'FOPENMODE' => 'fopen needs a macro for the mode string',
'IFDEFSINGLE', => 'use ifdef/ifndef for single macro checks',
'INCLUDEDUP', => 'same file is included again',
'INDENTATION' => 'wrong start column for code',
'LONGLINE' => "Line longer than $max_column",
@ -658,6 +659,11 @@ sub scanfile {
$line, length($1), $file, $l, "\/\/ comment");
}
if($l =~ /^\s*#\s*if\s+!?\s*defined\([a-zA-Z0-9_]+\)$/) {
checkwarn("IFDEFSINGLE",
$line, length($1), $file, $l, "use ifdef/ifndef for single macro checks");
}
if($l =~ /^(\#\s*include\s+)([\">].*[>}"])/) {
my ($pre, $path) = ($1, $2);
if($includes{$path}) {