diff --git a/util/check-format-test-negatives.c b/util/check-format-test-negatives.c index 280a7a0d99..c271bd77bd 100644 --- a/util/check-format-test-negatives.c +++ b/util/check-format-test-negatives.c @@ -30,6 +30,9 @@ /*- * allow extra SPC in format-tagged multi-line comment */ +/** allow extra '*' in comment opening */ +/*! allow extra '!' in comment opening */ + int f(void) /* * trailing multi-line comment */ diff --git a/util/check-format-test-positives.c b/util/check-format-test-positives.c index 135ca0e832..bf750930ac 100644 --- a/util/check-format-test-positives.c +++ b/util/check-format-test-positives.c @@ -40,19 +40,21 @@ *@ comment starting delimiter: /* inside multi-line comment *@ multi-line comment indent off by -1 *X*@ no spc after leading '*' in multi-line comment, reported unless sloppy-spc - *@0 more than two spaces after . in comment, reported unless sloppy-spc - *@0 more than two spaces after ? in comment, reported unless sloppy-spc - *@0 more than two spaces after ! in comment, reported unless sloppy-spc + *@0 more than two spaces after . in comment, no more reported + *@0 more than two spaces after ? in comment, no more reported + *@0 more than two spaces after ! in comment, no more reported */ /*@ multi-line comment end indent off by -1 (relative to comment start) */ */ /*@ unexpected comment ending delimiter outside comment */ +/*- '-' for formatted comment not allowed in intra-line comment */ /*@ comment line is 4 columns tooooooooooooooooo wide, reported unless sloppy-len */ /*@ comment line is 5 columns toooooooooooooooooooooooooooooooooooooooooooooo wide */ +#if ~0 /*@ '#if' with constant condition */ + #endif /*@ indent of preproc. directive off by 1 (must be 0) */ #define X (1 + 1) /*@0 extra space in body, reported unless sloppy-spc */ -#define X 1 /*@ extra space before body, reported unless sloppy-spc */ - #define Y 2 /*@2 indent of preproc. directive off by 1 (must be 0) */ \ -#define Z /*@ preprocessor directive within multi-line directive */ +#define Y 1 /*@ extra space before body, reported unless sloppy-spc */ \ +#define Z /*@2 preprocessor directive within multi-line directive */ typedef struct { /*@0 extra space in code, reported unless sloppy-spc */ - enum { /*@1 extra space in comment, no more reported */ + enum { /*@1 extra space in intra-line comment, no more reported */ w = 0 /*@ hanging expr indent off by 1, or 3 for lines after '{' */ && 1, /*@ hanging expr indent off by 3, or -1 for leading '&&' */ x = 1, /*@ hanging expr indent off by -1 */ @@ -344,7 +346,7 @@ void f_looong_body() ; /*@ 2 essentially blank lines before, if !sloppy-spc */ } /*@ function body length > 200 lines */ -#if 0 /*@0 unclosed #if */ +#if X /*@0 unclosed #if */ struct t { /*@0 unclosed brace at decl/block level */ enum { /*@0 unclosed brace at enum/expression level */ v = (1 /*@0 unclosed parenthesis */ diff --git a/util/check-format.pl b/util/check-format.pl index 285c1f1e46..a997460396 100755 --- a/util/check-format.pl +++ b/util/check-format.pl @@ -606,8 +606,8 @@ while (<>) { # loop over all lines of all input files # detect end of comment, must be within multi-line comment, check if it is preceded by non-whitespace text if ((my ($head, $tail) = m|^(.*?)\*/(.*)$|) && $1 ne '/') { # ending comment: '*/' - report("neither space nor '*' before '*/'") if $head =~ m/[^*\s]$/; - report("missing space after '*/'") if $tail =~ m/^[^\s,;)}\]]/; # no space or ,;)}] after '*/' + report("missing space or '*' before '*/'") if $head =~ m/[^*\s]$/; + report("missing space (or ',', ';', ')', '}', ']') after '*/'") if $tail =~ m/^[^\s,;)}\]]/; # no space or ,;)}] after '*/' if (!($head =~ m|/\*|)) { # not begin of comment '/*', which is is handled below if ($in_comment == 0) { report("unexpected '*/' outside comment"); @@ -632,7 +632,7 @@ while (<>) { # loop over all lines of all input files if (my ($head, $opt_minus, $tail) = m|^(.*?)/\*(-?)(.*)$|) { # begin of comment: '/*' report("missing space before '/*'") if $head =~ m/[^\s(\*]$/; # not space, '(', or or '*' (needed to allow '*/') before comment delimiter - report("missing space, '*' or '!' after '/*' or '/*-'") if $tail =~ m/^[^*\s!$self_test_exception]/; + report("missing space, '*', or '!' after '/*$opt_minus'") if $tail =~ m/^[^\s*!$self_test_exception]/; my $cmt_text = $opt_minus.$tail; # preliminary if ($in_comment > 0) { report("unexpected '/*' inside multi-line comment"); @@ -705,6 +705,8 @@ while (<>) { # loop over all lines of all input files } $in_preproc++; report("indent = $count != 0 for '#'") if $count != 0; + report("'#$preproc_directive' with constant condition") + if $preproc_directive =~ m/^(if|elif)$/ && m/^[\W0-9]+$/ && !$trailing_backslash; $preproc_if_nesting-- if $preproc_directive =~ m/^(else|elif|endif)$/; if ($preproc_if_nesting < 0) { $preproc_if_nesting = 0; @@ -978,8 +980,6 @@ while (<>) { # loop over all lines of all input files if (m/(['"]|([\+\-\*\/\/%\&\|\^<>]\s*)?\W[0-9]+L?|\WNULL)\s*([\!<>=]=|[<=>])([<>]?)/ && $2 eq "" && (($3 ne "<" && $3 ne "='" && $3 ne ">") || $4 eq "")); - # TODO report #if 0 and #if 1 - # TODO report needless use of parentheses, while # macro parameters should always be in parens (except when passed on), e.g., '#define ID(x) (x)'