[clang-tools-extra] [clang-tidy] Fix readability-identifier-naming FP on function templates (PR #198517)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 20 03:35:42 PDT 2026
https://github.com/CarvedCoder updated https://github.com/llvm/llvm-project/pull/198517
>From c492fa7130c284acb0594b6813a4d10957672ada Mon Sep 17 00:00:00 2001
From: CarvedCoder <shreyansbehera84 at gmail.com>
Date: Tue, 19 May 2026 19:10:26 +0530
Subject: [PATCH] [clang-tidy] Fix readability-identifier-naming FP on function
templates
---
.../readability/IdentifierNamingCheck.cpp | 5 +++++
.../identifier-naming-function-template.cpp | 19 +++++++++++++++++++
2 files changed, 24 insertions(+)
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-function-template.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index a356e1390b62d..76068127e50a5 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -11,6 +11,7 @@
#include "../GlobList.h"
#include "../utils/ASTUtils.h"
#include "clang/AST/CXXInheritance.h"
+#include "clang/AST/DeclTemplate.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/ArrayRef.h"
@@ -1289,6 +1290,10 @@ StyleKind IdentifierNamingCheck::findStyleKind(
return undefinedStyle(NamingStyles);
}
+ if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
+ return findStyleKind(FTD->getTemplatedDecl(), NamingStyles,
+ IgnoreMainLikeFunctions, CheckAnonFieldInParentScope);
+
if (const auto *Decl = dyn_cast<FunctionDecl>(D)) {
if (Decl->isMain())
return SK_Invalid;
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-function-template.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-function-template.cpp
new file mode 100644
index 0000000000000..de5848cbcf44e
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-function-template.cpp
@@ -0,0 +1,19 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-identifier-naming %t -- \
+// RUN: -config='{CheckOptions: { \
+// RUN: readability-identifier-naming.DefaultCase: lower_case, \
+// RUN: readability-identifier-naming.ConstexprFunctionCase: UPPER_CASE, \
+// RUN: readability-identifier-naming.TemplateParameterCase: CamelCase \
+// RUN: }}'
+
+// Regression test for function template classification with DefaultCase.
+// Previously FunctionTemplateDecl fell through to DefaultCase instead of
+// delegating to the underlying FunctionDecl.
+
+template <typename T>
+constexpr void GOOD_NAME(const T &) noexcept {}
+
+// No warning expected for TEST_FUNC.
+
+template <typename T>
+constexpr void bad_name(const T &) noexcept {}
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for constexpr function 'bad_name'
More information about the cfe-commits
mailing list