Author: Zeyi Xu
Date: 2026-04-10T12:03:39Z
New Revision: 8f341cc57dec88ef49cdff44b0490728d251536f

URL: 
https://github.com/llvm/llvm-project/commit/8f341cc57dec88ef49cdff44b0490728d251536f
DIFF: 
https://github.com/llvm/llvm-project/commit/8f341cc57dec88ef49cdff44b0490728d251536f.diff

LOG: [clang-tidy] Fix readability-identifier-naming FP with DefaultCase on 
function templates (#189788)

Closes #189755

---------

Co-authored-by: EugeneZelenko <[email protected]>
Co-authored-by: Daniil Dudkin <[email protected]>

Added: 
    
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-template-method-default.cpp

Modified: 
    clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
    clang-tools-extra/docs/ReleaseNotes.rst

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 871eaeec69021..a356e1390b62d 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1303,6 +1303,13 @@ StyleKind IdentifierNamingCheck::findStyleKind(
       return SK_Function;
   }
 
+  // Ignore template wrapper decls. Their underlying decls are checked with the
+  // right naming kind, checking the wrappers too can fall back to DefaultCase
+  // and emit diagnostic for the same identifier.
+  if (isa<FunctionTemplateDecl, ClassTemplateDecl, VarTemplateDecl,
+          TypeAliasTemplateDecl>(D))
+    return SK_Invalid;
+
   if (isa<TemplateTypeParmDecl>(D)) {
     if (NamingStyles[SK_TypeTemplateParameter])
       return SK_TypeTemplateParameter;

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7b47643a47c75..17a5b006d4b8f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -473,8 +473,12 @@ Changes in existing checks
   it easier to see which specific enumerators need explicit initialization.
 
 - Improved :doc:`readability-identifier-naming
-  <clang-tidy/checks/readability/identifier-naming>` check by fixing incorrect
-  naming style application to C++17 structured bindings.
+  <clang-tidy/checks/readability/identifier-naming>` check:
+
+  - Fixed incorrect naming style application to C++17 structured bindings.
+
+  - Fixed a false positive where function templates could be diagnosed as 
generic 
+    identifiers when `DefaultCase` was enabled.
 
 - Improved :doc:`readability-implicit-bool-conversion
   <clang-tidy/checks/readability/implicit-bool-conversion>` check:

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-template-method-default.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-template-method-default.cpp
new file mode 100644
index 0000000000000..e90ff5ecff3b0
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-template-method-default.cpp
@@ -0,0 +1,61 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t 
-std=c++20-or-later \
+// RUN:   --config='{CheckOptions: { \
+// RUN:     readability-identifier-naming.DefaultCase: lower_case, \
+// RUN:     readability-identifier-naming.ClassCase: CamelCase, \
+// RUN:     readability-identifier-naming.FunctionCase: camelBack, \
+// RUN:     readability-identifier-naming.GlobalVariableCase: camelBack, \
+// RUN:     readability-identifier-naming.MethodCase: camelBack, \
+// RUN:     readability-identifier-naming.TypeAliasCase: lower_case, \
+// RUN:     readability-identifier-naming.TypeAliasSuffix: _t, \
+// RUN:  }}'
+
+#define BadMacro
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for identifier 
'BadMacro' [readability-identifier-naming]
+// CHECK-FIXES: #define bad_macro
+
+class Foo {
+public:
+  template <typename t>
+  void doStuff() {}
+
+  template <typename t>
+  void DoStuff() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for method 
'DoStuff' [readability-identifier-naming]
+  // CHECK-FIXES: void doStuff() {}
+};
+
+template <typename t>
+void freeFunction() {}
+
+template <typename t>
+void FreeFunction() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for function 
'FreeFunction' [readability-identifier-naming]
+// CHECK-FIXES: void freeFunction() {}
+
+template <typename t>
+class GoodClass {};
+
+template <typename t>
+class badClass {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'badClass' [readability-identifier-naming]
+// CHECK-FIXES: class BadClass {};
+
+template <typename t>
+int goodVariable = 0;
+
+template <typename t>
+int BadVariable = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global 
variable 'BadVariable' [readability-identifier-naming]
+// CHECK-FIXES: int badVariable = 0;
+
+template <typename t>
+using good_alias_t = int;
+
+template <typename t>
+using BadAlias = int;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 
'BadAlias' [readability-identifier-naming]
+// CHECK-FIXES: using bad_alias_t = int;
+
+int BadGlobal = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global 
variable 'BadGlobal' [readability-identifier-naming]
+// CHECK-FIXES: int badGlobal = 0;


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to