[clang-tools-extra] Support renaming designated initializers (PR #86976)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 28 09:53:10 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
@llvm/pr-subscribers-clang-tools-extra
Author: Edwin Vane (revane)
<details>
<summary>Changes</summary>
Until now, they were just ignored by RenamerClangTidyCheck.
---
Full diff: https://github.com/llvm/llvm-project/pull/86976.diff
2 Files Affected:
- (modified) clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp (+19)
- (modified) clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp (+8)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index da1433aa2d05d4..e3409dfbb8f677 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -367,6 +367,25 @@ class RenamerClangTidyVisitor
return true;
}
+ bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) {
+ for (const auto &Designator : Expr->designators()) {
+ if (!Designator.isFieldDesignator())
+ continue;
+ auto *FieldDecl = Designator.getFieldDecl();
+ if (!FieldDecl)
+ continue;
+ auto *II = FieldDecl->getIdentifier();
+ if (!II)
+ continue;
+ SourceRange FixLocation{
+ Designator.getFieldLoc(),
+ Designator.getFieldLoc().getLocWithOffset(II->getLength())};
+ Check->addUsage(FieldDecl, FixLocation, SM);
+ }
+
+ return true;
+ }
+
private:
RenamerClangTidyCheck *Check;
const SourceManager *SM;
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 84bf7764583e80..9c390e544c2abd 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
@@ -755,3 +755,11 @@ 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_s{ .SomeMember = 1 };
+// CHECK-FIXES: {{^}}Some_struct g_s{ .some_member = 1 };
``````````
</details>
https://github.com/llvm/llvm-project/pull/86976
More information about the cfe-commits
mailing list