checkpatch: exclude forward declarations of const structs
PATCH 1/1 checkpatch: exclude forward declarations of const structs
Limit checkpatch warnings for normally-const structs by excluding patterns consistent with forward declarations.
For example, the forward declaration struct regmap_access_table; in a header file currently generates a warning recommending that it is generally declared as const; however, this would apply a useless type qualifier in the empty declaration const struct regmap_access_table;, and subsequently generate compiler warnings.
--- scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +2 -2
@@ -7502,10 +7502,10 @@ sub process { } # check for various structs that are normally const (ops, kgdb, device_tree) -# and avoid what seem like struct definitions 'struct foo {' +# and avoid what seem like struct definitions 'struct foo {' or forward declarations 'struct foo;' if (defined($const_structs) && $line !~ /\bconst\b/ && - $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { + $line =~ /\bstruct\s+($const_structs)\b(?!\s*(\{|;))/) { WARN("CONST_STRUCT", "struct $1 should normally be const\n" . $herecurr); }
Signature · 1 line
2.53.0.1118.gaef5881109-goog
Joe Perches
maintainerQuoted 11 lines · Taylor Nelms
```
Limit checkpatch warnings for normally-const structs by excluding patterns consistent with forward declarations.For example, the forward declaration
struct regmap_access_table;in a header file currently generates a warning recommending that it is generally declared as const; however, this would apply a useless type qualifier in the empty declarationconst struct regmap_access_table;, and subsequently generate compiler warnings.
Seems sensible, thanks but:
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0
[]
scripts/checkpatch.pl sub process { · line 7508
Quoted 10 lines
scripts/checkpatch.pl +2
-2@@ -7502,10 +7502,10 @@ sub process { } # check for various structs that are normally const (ops, kgdb, device_tree) -# and avoid what seem like struct definitions 'struct foo {' +# and avoid what seem like struct definitions 'struct foo {' or forward declarations 'struct foo;' if (defined($const_structs) && $line !~ /\bconst\b/ && - $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { + $line =~ /\bstruct\s+($const_structs)\b(?!\s*(\{|;))/) {
Prefer using (?:\{|;) to avoid capture groups or maybe [\{;]
PATCH v2 1/1 checkpatch: exclude forward declarations of const structs
Limit checkpatch warnings for normally-const structs by excluding patterns consistent with forward declarations.
For example, the forward declaration struct regmap_access_table; in a header file currently generates a warning recommending that it is generally declared as const; however, this would apply a useless type qualifier in the empty declaration const struct regmap_access_table;, and subsequently generate compiler warnings.
---
Changelog since v1:
- Changed capturing group to character class in regex.
scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +2 -2
@@ -7502,10 +7502,10 @@ sub process { } # check for various structs that are normally const (ops, kgdb, device_tree) -# and avoid what seem like struct definitions 'struct foo {' +# and avoid what seem like struct definitions 'struct foo {' or forward declarations 'struct foo;' if (defined($const_structs) && $line !~ /\bconst\b/ && - $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { + $line =~ /\bstruct\s+($const_structs)\b(?!\s*[\{;])/) { WARN("CONST_STRUCT", "struct $1 should normally be const\n" . $herecurr); }
Signature · 1 line
2.53.0.1118.gaef5881109-goog
Quoted 10 lines · Taylor Nelms
Limit checkpatch warnings for normally-const structs by excluding patterns consistent with forward declarations.
For example, the forward declaration
struct regmap_access_table;in a header file currently generates a warning recommending that it is generally declared as const; however, this would apply a useless type qualifier in the empty declarationconst struct regmap_access_table;, and subsequently generate compiler warnings.
Quoted 27 lines
---
Changelog since v1:
- Changed capturing group to character class in regex.scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)scripts/checkpatch.pl +2
-2@@ -7502,10 +7502,10 @@ sub process { } # check for various structs that are normally const (ops, kgdb, device_tree) -# and avoid what seem like struct definitions 'struct foo {' +# and avoid what seem like struct definitions 'struct foo {' or forward declarations 'struct foo;' if (defined($const_structs) && $line !~ /\bconst\b/ && - $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { + $line =~ /\bstruct\s+($const_structs)\b(?!\s*[\{;])/) { WARN("CONST_STRUCT", "struct $1 should normally be const\n" . $herecurr); }```