[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 closed https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 edited https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 resolved https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/65558: >From f25a855ac2d3ec4b89f55a08e415596b3b65f142 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 7 Sep 2023 10:14:28 +0800 Subject: [PATCH 1/3] [clang-tidy][modernize-use-using]fix function pointer typedef correctly --- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp | 6 -- clang-tools-extra/docs/ReleaseNotes.rst| 3 +++ .../test/clang-tidy/checkers/modernize/use-using.cpp | 7 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp index c1af8b5bfa11ca..22dc9e21cab9d5 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 ) { 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 a2cde526a8c04d..90a782fa53b257 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -246,6 +246,9 @@ Changes in existing checks ` check to accurately generate fixes for reordering arguments. +- Improved :doc:`modernize-use-using` + check to fix function pointer ``typedef`` correctly. + - Improved :doc:`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 14469e31c82624..01f22f26c034eb 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) >From 6aef0e7f658ada3f95f2fdf9deae89310a2a9038 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 7 Sep 2023 13:56:12 +0800 Subject: [PATCH 2/3] fix according to comments --- clang-tools-extra/docs/ReleaseNotes.rst | 5 +++-- .../test/clang-tidy/checkers/modernize/use-using.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 90a782fa53b257..998e763d792af6 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -246,8 +246,9 @@ Changes in existing checks ` check to accurately generate fixes for reordering arguments. -- Improved :doc:`modernize-use-using` - check to fix function pointer ``typedef`` correctly. +- Improved :doc:`modernize-use-using + ` check to fix function pointer + ``typedef`` correctly. - Improved :doc:`performance-faster-string-find ` check to properly escape 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 01f22f26c034eb..f1f62b4051a8e7 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 @@ -319,5 +319,5 @@ 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) +// CHECK-FIXES: using ISSUE_65055_1 = void (*)(int); +// CHECK-FIXES: using ISSUE_65055_2 = bool
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
HerrCai0907 wrote: > This is weird issues because it always happen when two typedefs are one after > other. ```c++ typedef void (*ISSUE_65055_1)(int); typedef bool (*ISSUE_65055_2)(int); typedef void VOID; ``` The typedef matcher will match following position: ``` TypedefDecl 0x1610ba960 col:16 ISSUE_65055_1 'void (*)(int)' TypedefDecl 0x1610bab30 col:16 ISSUE_65055_2 'bool (*)(int)' TypedefDecl 0x1610bab98 col:14 VOID 'void' ``` That means typedef normal type is from `typedef` to the end of original type but for function pointer is from `typedef` to the end. https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/PiotrZSL approved this pull request. LGTM, This is weird issues because it always happen when two typedefs are one after other. I would personally thing more that LastReplacementEnd is to big, not too small. But if tests check this properly, then I'm fine with it. https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
@@ -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); PiotrZSL wrote: use start character in CHECK_FIXES, otherwise this could also match case were typedef is not deleted. `// CHECK-FIXES: {{^}}using ISSUE_65055_1 = void (*)(int);{{$}}` https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/PiotrZSL resolved https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
@@ -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); PiotrZSL wrote: ok https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 review_requested https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/65558: >From f25a855ac2d3ec4b89f55a08e415596b3b65f142 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 7 Sep 2023 10:14:28 +0800 Subject: [PATCH 1/2] [clang-tidy][modernize-use-using]fix function pointer typedef correctly --- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp | 6 -- clang-tools-extra/docs/ReleaseNotes.rst| 3 +++ .../test/clang-tidy/checkers/modernize/use-using.cpp | 7 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp index c1af8b5bfa11cac..22dc9e21cab9d5a 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 ) { 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 a2cde526a8c04d9..90a782fa53b257d 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -246,6 +246,9 @@ Changes in existing checks ` check to accurately generate fixes for reordering arguments. +- Improved :doc:`modernize-use-using` + check to fix function pointer ``typedef`` correctly. + - Improved :doc:`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 14469e31c826249..01f22f26c034ebe 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) >From 6aef0e7f658ada3f95f2fdf9deae89310a2a9038 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 7 Sep 2023 13:56:12 +0800 Subject: [PATCH 2/2] fix according to comments --- clang-tools-extra/docs/ReleaseNotes.rst | 5 +++-- .../test/clang-tidy/checkers/modernize/use-using.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 90a782fa53b257d..998e763d792af6b 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -246,8 +246,9 @@ Changes in existing checks ` check to accurately generate fixes for reordering arguments. -- Improved :doc:`modernize-use-using` - check to fix function pointer ``typedef`` correctly. +- Improved :doc:`modernize-use-using + ` check to fix function pointer + ``typedef`` correctly. - Improved :doc:`performance-faster-string-find ` check to properly escape 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 01f22f26c034ebe..f1f62b4051a8e78 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 @@ -319,5 +319,5 @@ 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) +// CHECK-FIXES: using ISSUE_65055_1 = void (*)(int); +// CHECK-FIXES: using ISSUE_65055_2
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 resolved https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 resolved https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/65558: >From f25a855ac2d3ec4b89f55a08e415596b3b65f142 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 7 Sep 2023 10:14:28 +0800 Subject: [PATCH 1/2] [clang-tidy][modernize-use-using]fix function pointer typedef correctly --- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp | 6 -- clang-tools-extra/docs/ReleaseNotes.rst| 3 +++ .../test/clang-tidy/checkers/modernize/use-using.cpp | 7 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp index c1af8b5bfa11cac..22dc9e21cab9d5a 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 ) { 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 a2cde526a8c04d9..90a782fa53b257d 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -246,6 +246,9 @@ Changes in existing checks ` check to accurately generate fixes for reordering arguments. +- Improved :doc:`modernize-use-using` + check to fix function pointer ``typedef`` correctly. + - Improved :doc:`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 14469e31c826249..01f22f26c034ebe 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) >From f46eb6ef4305c5362577d0da70b592237e3c180b Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 7 Sep 2023 13:56:12 +0800 Subject: [PATCH 2/2] fix according to comments --- clang-tools-extra/docs/ReleaseNotes.rst | 5 +++-- .../test/clang-tidy/checkers/modernize/use-using.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 90a782fa53b257d..998e763d792af6b 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -246,8 +246,9 @@ Changes in existing checks ` check to accurately generate fixes for reordering arguments. -- Improved :doc:`modernize-use-using` - check to fix function pointer ``typedef`` correctly. +- Improved :doc:`modernize-use-using + ` check to fix function pointer + ``typedef`` correctly. - Improved :doc:`performance-faster-string-find ` check to properly escape 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 01f22f26c034ebe..f1f62b4051a8e78 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 @@ -319,5 +319,5 @@ 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) +// CHECK-FIXES: using ISSUE_65055_1 = void (*)(int); +// CHECK-FIXES: using ISSUE_65055_2
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
@@ -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); HerrCai0907 wrote: length of variable names is not related with this bugs. https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
@@ -246,6 +246,9 @@ Changes in existing checks ` check to accurately generate fixes for reordering arguments. +- Improved :doc:`modernize-use-using` PiotrZSL wrote: put space before <, juts for visibility. https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
@@ -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); PiotrZSL wrote: Original issue were mainly with single character variable names, maybe test something like: `typedef void (*C)(int);` https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
@@ -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) PiotrZSL wrote: put `;` at the end of CHECK-FIXES, just to verify that it wont be removed. https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/github-actions[bot] labeled https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 review_requested https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 review_requested https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 review_requested https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 review_requested https://github.com/llvm/llvm-project/pull/65558 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][modernize-use-using]fix function pointer typedef correctly (PR #65558)
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/65558: Fixed #65055 >From f25a855ac2d3ec4b89f55a08e415596b3b65f142 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 7 Sep 2023 10:14:28 +0800 Subject: [PATCH] [clang-tidy][modernize-use-using]fix function pointer typedef correctly --- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp | 6 -- clang-tools-extra/docs/ReleaseNotes.rst| 3 +++ .../test/clang-tidy/checkers/modernize/use-using.cpp | 7 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp index c1af8b5bfa11cac..22dc9e21cab9d5a 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 ) { 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 a2cde526a8c04d9..90a782fa53b257d 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -246,6 +246,9 @@ Changes in existing checks ` check to accurately generate fixes for reordering arguments. +- Improved :doc:`modernize-use-using` + check to fix function pointer ``typedef`` correctly. + - Improved :doc:`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 14469e31c826249..01f22f26c034ebe 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) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits