Using 'const <type> const *' is generally meant to be written 'const <type> * const'. Add a test for the miswritten form.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -323,6 +323,7 @@ our $Operators = qr{ · 322 unmodified lines | ||
| 323 | 323 | |
| 324 | 324 | our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; |
| 325 | 325 | |
| 326 | +our $BasicType; | |
| 326 | 327 | our $NonptrType; |
| 327 | 328 | our $NonptrTypeMisordered; |
| 328 | 329 | our $NonptrTypeWithAttr; |
| @@ -514,6 +515,11 @@ sub build_types { · 185 unmodified lines | ||
| 514 | 515 | my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; |
| 515 | 516 | my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; |
| 516 | 517 | $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; |
| 518 | + $BasicType = qr{ | |
| 519 | + (?:$typeOtherOSTypedefs\b)| | |
| 520 | + (?:$typeTypedefs\b)| | |
| 521 | + (?:${all}\b) | |
| 522 | + }x; | |
| 517 | 523 | $NonptrType = qr{ |
| 518 | 524 | (?:$Modifier\s+|const\s+)* |
| 519 | 525 | (?: |
| @@ -3192,6 +3198,18 @@ sub process { · 2672 unmodified lines | ||
| 3192 | 3198 | $herecurr); |
| 3193 | 3199 | } |
| 3194 | 3200 | |
| 3201 | +# check for const <foo> const where <foo> is not a pointer or array type | |
| 3202 | + if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) { | |
| 3203 | + my $found = $1; | |
| 3204 | + if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) { | |
| 3205 | + WARN("CONST_CONST", | |
| 3206 | + "'const $found const *' should probably be 'const $found * const'\n" . $herecurr); | |
| 3207 | + } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) { | |
| 3208 | + WARN("CONST_CONST", | |
| 3209 | + "'const $found const' should probably be 'const $found'\n" . $herecurr); | |
| 3210 | + } | |
| 3211 | + } | |
| 3212 | + | |
| 3195 | 3213 | # check for non-global char *foo[] = {"bar", ...} declarations. |
| 3196 | 3214 | if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { |
| 3197 | 3215 | WARN("STATIC_CONST_CHAR_ARRAY", |