aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra
diff options
context:
space:
mode:
authorCongcong Cai <congcongcai0907@163.com>2023-09-07 17:06:28 +0800
committerGitHub <noreply@github.com>2023-09-07 17:06:28 +0800
commit31ded495271e5869d619da851a351c9f6f05b2d4 (patch)
tree3282cd228a8b30308097bd3bd90cb2254b935edb /clang-tools-extra
parent741c1278175b9354442cd2143e1452714dc020a2 (diff)
downloadllvm-31ded495271e5869d619da851a351c9f6f05b2d4.zip
llvm-31ded495271e5869d619da851a351c9f6f05b2d4.tar.gz
llvm-31ded495271e5869d619da851a351c9f6f05b2d4.tar.bz2
[clang-tidy][modernize-use-using]fix function pointer typedef correctly (#65558)
Fixed #65055 For normal type, typedef is from typedef to the end of original type, but for function pointer it is from typedef to the end. So it needs to consider alias name length for normal type.
Diffstat (limited to 'clang-tools-extra')
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp6
-rw-r--r--clang-tools-extra/docs/ReleaseNotes.rst4
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp7
3 files changed, 15 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index c1af8b5..22dc9e2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -120,8 +120,10 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
Type.substr(0, FirstTypedefType.size()) == FirstTypedefType)
Type = FirstTypedefName + Type.substr(FirstTypedefType.size() + 1);
}
- if (!ReplaceRange.getEnd().isMacroID())
- LastReplacementEnd = ReplaceRange.getEnd().getLocWithOffset(Name.size());
+ if (!ReplaceRange.getEnd().isMacroID()) {
+ const SourceLocation::IntTy Offset = MatchedDecl->getFunctionType() ? 0 : Name.size();
+ LastReplacementEnd = ReplaceRange.getEnd().getLocWithOffset(Offset);
+ }
auto Diag = diag(ReplaceRange.getBegin(), UseUsingWarning);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index a2cde52..998e763 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -246,6 +246,10 @@ Changes in existing checks
<clang-tidy/checks/modernize/use-std-print>` check to accurately generate
fixes for reordering arguments.
+- Improved :doc:`modernize-use-using
+ <clang-tidy/checks/modernize/use-using>` check to fix function pointer
+ ``typedef`` correctly.
+
- Improved :doc:`performance-faster-string-find
<clang-tidy/checks/performance/faster-string-find>` check to properly escape
single quotes.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 14469e3..f7db0af 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -314,3 +314,10 @@ typedef struct { struct { int a; struct { struct { int b; } c; int d; } e; } f;
typedef struct { struct { int a; } b; union { int c; float d; struct { int e; }; }; struct { double f; } g; } PR50990_siblings;
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
// CHECK-FIXES: using PR50990_siblings = struct { struct { int a; } b; union { int c; float d; struct { int e; }; }; struct { double f; } g; };
+
+typedef void (*ISSUE_65055_1)(int);
+typedef bool (*ISSUE_65055_2)(int);
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: {{^}}using ISSUE_65055_1 = void (*)(int);{{$}}
+// CHECK-FIXES: {{^}}using ISSUE_65055_2 = bool (*)(int);{{$}}