[clang-tools-extra] Support renaming designated initializers (PR #86976)
Edwin Vane via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 2 05:34:01 PDT 2024
https://github.com/revane updated https://github.com/llvm/llvm-project/pull/86976
>From f8604d450fa3852d5c684bc8ada228a07ce6ccf5 Mon Sep 17 00:00:00 2001
From: Edwin Vane <revane at google.com>
Date: Thu, 28 Mar 2024 09:24:34 -0400
Subject: [PATCH] Support renaming designated initializers
Until now, they were just ignored by RenamerClangTidyCheck.
---
.../clang-tidy/utils/RenamerClangTidyCheck.cpp | 18 ++++++++++++++++++
clang-tools-extra/docs/ReleaseNotes.rst | 3 ++-
.../checkers/readability/identifier-naming.cpp | 10 ++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index da1433aa2d05d4..1edab9504b0ec0 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -367,6 +367,24 @@ class RenamerClangTidyVisitor
return true;
}
+ bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) {
+ for (const auto &Designator : Expr->designators()) {
+ if (!Designator.isFieldDesignator())
+ continue;
+ FieldDecl *FD = Designator.getFieldDecl();
+ if (!FD)
+ continue;
+ IdentifierInfo *II = FD->getIdentifier();
+ if (!II)
+ continue;
+ SourceRange FixLocation{Designator.getFieldLoc(),
+ Designator.getFieldLoc()};
+ Check->addUsage(FD, FixLocation, SM);
+ }
+
+ return true;
+ }
+
private:
RenamerClangTidyCheck *Check;
const SourceManager *SM;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 309b844615a121..e076281bd5fafe 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -254,7 +254,8 @@ Changes in existing checks
- Improved :doc:`readability-identifier-naming
<clang-tidy/checks/readability/identifier-naming>` check in `GetConfigPerFile`
mode by resolving symbolic links to header files. Fixed handling of Hungarian
- Prefix when configured to `LowerCase`.
+ Prefix when configured to `LowerCase`. Added support for renaming designated
+ initializers.
- Improved :doc:`readability-implicit-bool-conversion
<clang-tidy/checks/readability/implicit-bool-conversion>` check to provide
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
index d2e89a7c9855c9..57ef4aae5ddb78 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -766,3 +766,13 @@ STATIC_MACRO void someFunc(MyFunPtr, const MyFunPtr****) {}
// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(my_fun_ptr_t, const my_fun_ptr_t****) {}
#undef STATIC_MACRO
}
+
+struct Some_struct {
+ int SomeMember;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for public member 'SomeMember' [readability-identifier-naming]
+// CHECK-FIXES: {{^}} int some_member;
+};
+Some_struct g_s1{ .SomeMember = 1 };
+// CHECK-FIXES: {{^}}Some_struct g_s1{ .some_member = 1 };
+Some_struct g_s2{.SomeMember=1};
+// CHECK-FIXES: {{^}}Some_struct g_s2{.some_member=1};
More information about the cfe-commits
mailing list