File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
108108 << MatchedDecl;
109109 if (*InitializationString != nullptr )
110110 Diagnostic << FixItHint::CreateInsertion (
111- utils::lexer::findNextTerminator (MatchedDecl->getLocation (),
111+ utils::lexer::findNextTerminator (MatchedDecl->getEndLoc (),
112112 *Result.SourceManager ,
113113 Result.Context ->getLangOpts ()),
114114 *InitializationString);
Original file line number Diff line number Diff line change @@ -307,6 +307,10 @@ Changes in existing checks
307307 an additional matcher that generalizes the copy-and-swap idiom pattern
308308 detection.
309309
310+ - Improved :doc: `cppcoreguidelines-init-variables
311+ <clang-tidy/checks/cppcoreguidelines/init-variables>` check by fixing the
312+ insertion location for function pointers with multiple parameters.
313+
310314- Improved :doc: `cppcoreguidelines-prefer-member-initializer
311315 <clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
312316 avoid false positives on inherited members in class templates.
Original file line number Diff line number Diff line change @@ -148,3 +148,23 @@ namespace gh112089 {
148148 }
149149} // namespace gh112089
150150
151+ namespace gh161978 {
152+ void test () {
153+ bool (*fp1)(int );
154+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp1' is not initialized [cppcoreguidelines-init-variables]
155+ // CHECK-FIXES: bool (*fp1)(int) = nullptr;
156+ bool (*fp2)(int , int );
157+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp2' is not initialized [cppcoreguidelines-init-variables]
158+ // CHECK-FIXES: bool (*fp2)(int, int) = nullptr;
159+ bool (*fp3)(int , int , int );
160+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp3' is not initialized [cppcoreguidelines-init-variables]
161+ // CHECK-FIXES: bool (*fp3)(int, int, int) = nullptr;
162+ bool (*fp4)(int , int , int , ...);
163+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp4' is not initialized [cppcoreguidelines-init-variables]
164+ // CHECK-FIXES: bool (*fp4)(int, int, int, ...) = nullptr;
165+ bool (*fp5)(int , int ), (*fp6)(int , int );
166+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp5' is not initialized [cppcoreguidelines-init-variables]
167+ // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: variable 'fp6' is not initialized [cppcoreguidelines-init-variables]
168+ // CHECK-FIXES: bool (*fp5)(int, int) = nullptr, (*fp6)(int, int) = nullptr;
169+ }
170+ }
You can’t perform that action at this time.
0 commit comments