[PATCH] D157190: [clang-tidy] Fixed false-negative in readability-identifier-naming
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 6 02:26:44 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2111577d4dfc: [clang-tidy] Fixed false-negative in readability-identifier-naming (authored by PiotrZSL).
Changed prior to commit:
https://reviews.llvm.org/D157190?vs=547503&id=547536#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157190/new/
https://reviews.llvm.org/D157190
Files:
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -707,3 +707,19 @@
task ImplicitDeclTest(async_obj &a_object) {
co_await a_object; // CHECK-MESSAGES-NOT: warning: invalid case style for local variable
}
+
+// Test scenario when canonical declaration will be a forward declaration
+struct ForwardDeclStruct;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'ForwardDeclStruct' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}struct forward_decl_struct;
+// CHECK-FIXES: {{^}}struct forward_decl_struct {
+struct ForwardDeclStruct {
+};
+
+struct forward_declared_as_struct;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for class 'forward_declared_as_struct' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}struct CForwardDeclaredAsStruct;
+// CHECK-FIXES: {{^}}class CForwardDeclaredAsStruct {
+class forward_declared_as_struct {
+};
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -180,6 +180,10 @@
<clang-tidy/checks/modernize/loop-convert>` to support for-loops with
iterators initialized by free functions like ``begin``, ``end``, or ``size``.
+- Improved the :doc:`readability-identifier-naming
+ <clang-tidy/checks/readability/identifier-naming>` check to emit proper
+ warnings when a type forward declaration precedes its definition.
+
Removed checks
^^^^^^^^^^^^^^
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1140,30 +1140,28 @@
if (Decl->isAnonymousStructOrUnion())
return SK_Invalid;
- if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
- return SK_Invalid;
-
- if (Decl->hasDefinition() && Decl->isAbstract() &&
- NamingStyles[SK_AbstractClass])
- return SK_AbstractClass;
+ if (const auto *Definition = Decl->getDefinition()) {
+ if (Definition->isAbstract() && NamingStyles[SK_AbstractClass])
+ return SK_AbstractClass;
- if (Decl->isStruct() && NamingStyles[SK_Struct])
- return SK_Struct;
+ if (Definition->isStruct() && NamingStyles[SK_Struct])
+ return SK_Struct;
- if (Decl->isStruct() && NamingStyles[SK_Class])
- return SK_Class;
+ if (Definition->isStruct() && NamingStyles[SK_Class])
+ return SK_Class;
- if (Decl->isClass() && NamingStyles[SK_Class])
- return SK_Class;
+ if (Definition->isClass() && NamingStyles[SK_Class])
+ return SK_Class;
- if (Decl->isClass() && NamingStyles[SK_Struct])
- return SK_Struct;
+ if (Definition->isClass() && NamingStyles[SK_Struct])
+ return SK_Struct;
- if (Decl->isUnion() && NamingStyles[SK_Union])
- return SK_Union;
+ if (Definition->isUnion() && NamingStyles[SK_Union])
+ return SK_Union;
- if (Decl->isEnum() && NamingStyles[SK_Enum])
- return SK_Enum;
+ if (Definition->isEnum() && NamingStyles[SK_Enum])
+ return SK_Enum;
+ }
return SK_Invalid;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157190.547536.patch
Type: text/x-patch
Size: 3574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230806/e405e265/attachment-0001.bin>
More information about the cfe-commits
mailing list