History

checkpatch: add test for repeated const uses

Using 'const <type> const *' is generally meant to be written 'const <type> * const'. Add a test for the miswritten form.

Joe Perches committed 11 years ago

Commit ab7e23f1 parent f34e4a41 file · +18 −0Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+18−0
@@ -323,6 +323,7 @@ our $Operators = qr{ · 322 unmodified lines
323 323
324our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;324our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
325 325
326our $BasicType;
326our $NonptrType;327our $NonptrType;
327our $NonptrTypeMisordered;328our $NonptrTypeMisordered;
328our $NonptrTypeWithAttr;329our $NonptrTypeWithAttr;
@@ -514,6 +515,11 @@ sub build_types { · 185 unmodified lines
514 my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)";515 my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)";
515 my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)";516 my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)";
516 $Modifier = qr{(?:$Attribute|$Sparse|$mods)};517 $Modifier = qr{(?:$Attribute|$Sparse|$mods)};
518 $BasicType = qr{
519 (?:$typeOtherOSTypedefs\b)|
520 (?:$typeTypedefs\b)|
521 (?:${all}\b)
522 }x;
517 $NonptrType = qr{523 $NonptrType = qr{
518 (?:$Modifier\s+|const\s+)*524 (?:$Modifier\s+|const\s+)*
519 (?:525 (?:
@@ -3192,6 +3198,18 @@ sub process { · 2672 unmodified lines
3192 $herecurr);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# check for non-global char *foo[] = {"bar", ...} declarations.3213# check for non-global char *foo[] = {"bar", ...} declarations.
3196 if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {3214 if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
3197 WARN("STATIC_CONST_CHAR_ARRAY",3215 WARN("STATIC_CONST_CHAR_ARRAY",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t