Skip to content

[clang-tidy] readability-identifier-naming - fix StructCase and UnionCase in C #65202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1151,13 +1151,15 @@ StyleKind IdentifierNamingCheck::findStyleKind(
return SK_Invalid;
}

if (const auto *Decl = dyn_cast<CXXRecordDecl>(D)) {
if (const auto *Decl = dyn_cast<RecordDecl>(D)) {
if (Decl->isAnonymousStructOrUnion())
return SK_Invalid;

if (const auto *Definition = Decl->getDefinition()) {
if (Definition->isAbstract() && NamingStyles[SK_AbstractClass])
return SK_AbstractClass;
if (const auto *CxxRecordDecl = dyn_cast<CXXRecordDecl>(Definition)) {
if (CxxRecordDecl->isAbstract() && NamingStyles[SK_AbstractClass])
return SK_AbstractClass;
}

if (Definition->isStruct() && NamingStyles[SK_Struct])
return SK_Struct;
Expand Down
8 changes: 5 additions & 3 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ Changes in existing checks
``length()`` method as an alternative to ``size()``.

- Improved :doc:`readability-identifier-naming
<clang-tidy/checks/readability/identifier-naming>` check to emit proper
warnings when a type forward declaration precedes its definition and
added support for ``Leading_upper_snake_case`` naming convention.
<clang-tidy/checks/readability/identifier-naming>` check to issue accurate
warnings when a type's forward declaration precedes its definition.
Additionally, it now provides appropriate warnings for ``struct`` and
``union`` in C, while also incorporating support for the
``Leading_upper_snake_case`` naming convention.

- Improved :doc:`readability-implicit-bool-conversion
<clang-tidy/checks/readability/implicit-bool-conversion>` check to take
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Checks: readability-identifier-naming
CheckOptions:
readability-identifier-naming.AbstractClassCase: CamelCase
readability-identifier-naming.StructCase: CamelCase
readability-identifier-naming.UnionCase: camelBack
readability-identifier-naming.ClassCase: CamelCase
readability-identifier-naming.ClassConstantCase: CamelCase
readability-identifier-naming.ClassMemberCase: CamelCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ struct MyStruct { int StructCase; };
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: invalid case style for public member 'StructCase' [readability-identifier-naming]
// CHECK-FIXES: {{^}}struct MyStruct { int iStructCase; };

struct shouldBeCamelCaseStruct { int iField; };
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'shouldBeCamelCaseStruct' [readability-identifier-naming]
// CHECK-FIXES: {{^}}struct ShouldBeCamelCaseStruct { int iField; };

union MyUnion { int UnionCase; long lUnionCase; };
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for public member 'UnionCase' [readability-identifier-naming]
// CHECK-FIXES: {{^}}union MyUnion { int iUnionCase; long lUnionCase; };
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for union 'MyUnion' [readability-identifier-naming]
// CHECK-MESSAGES: :[[@LINE-2]]:21: warning: invalid case style for public member 'UnionCase' [readability-identifier-naming]
// CHECK-FIXES: {{^}}union myUnion { int iUnionCase; long lUnionCase; };

//===----------------------------------------------------------------------===//
// C string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,14 @@ struct MyStruct { int StructCase; };
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: invalid case style for public member 'StructCase' [readability-identifier-naming]
// CHECK-FIXES: {{^}}struct MyStruct { int iStructCase; };

struct shouldBeCamelCaseStruct { int iField; };
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'shouldBeCamelCaseStruct' [readability-identifier-naming]
// CHECK-FIXES: {{^}}struct ShouldBeCamelCaseStruct { int iField; };

union MyUnion { int UnionCase; long lUnionCase; };
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for public member 'UnionCase' [readability-identifier-naming]
// CHECK-FIXES: {{^}}union MyUnion { int iUnionCase; long lUnionCase; };
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for union 'MyUnion' [readability-identifier-naming]
// CHECK-MESSAGES: :[[@LINE-2]]:21: warning: invalid case style for public member 'UnionCase' [readability-identifier-naming]
// CHECK-FIXES: {{^}}union myUnion { int iUnionCase; long lUnionCase; };

//===----------------------------------------------------------------------===//
// C string
Expand Down