PiotrZSL created this revision.
PiotrZSL added reviewers: carlosgalvezp, njames93.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Issue were cased by checking if canonical declaration of record is a
definition. Unfortunetly when forward declarations were used, it were
not a definition. Changed to use hasDefinition instead.

Fixes: #64463


Repository:
  rG LLVM Github Monorepo

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,13 @@
 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
+class class_with_forward_decl;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'class_with_forward_decl' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl;
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl {
+class class_with_forward_decl {
+  int __value;
+};
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   <clang-tidy/checks/bugprone/reserved-identifier>`, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- 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
@@ -1137,14 +1137,10 @@
   }
 
   if (const auto *Decl = dyn_cast<CXXRecordDecl>(D)) {
-    if (Decl->isAnonymousStructOrUnion())
+    if (Decl->isAnonymousStructOrUnion() || !Decl->hasDefinition())
       return SK_Invalid;
 
-    if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
-      return SK_Invalid;
-
-    if (Decl->hasDefinition() && Decl->isAbstract() &&
-        NamingStyles[SK_AbstractClass])
+    if (Decl->isAbstract() && NamingStyles[SK_AbstractClass])
       return SK_AbstractClass;
 
     if (Decl->isStruct() && NamingStyles[SK_Struct])


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,13 @@
 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
+class class_with_forward_decl;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'class_with_forward_decl' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl;
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl {
+class class_with_forward_decl {
+  int __value;
+};
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   <clang-tidy/checks/bugprone/reserved-identifier>`, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- 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
@@ -1137,14 +1137,10 @@
   }
 
   if (const auto *Decl = dyn_cast<CXXRecordDecl>(D)) {
-    if (Decl->isAnonymousStructOrUnion())
+    if (Decl->isAnonymousStructOrUnion() || !Decl->hasDefinition())
       return SK_Invalid;
 
-    if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
-      return SK_Invalid;
-
-    if (Decl->hasDefinition() && Decl->isAbstract() &&
-        NamingStyles[SK_AbstractClass])
+    if (Decl->isAbstract() && NamingStyles[SK_AbstractClass])
       return SK_AbstractClass;
 
     if (Decl->isStruct() && NamingStyles[SK_Struct])
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to