[clang-tools-extra] [clang-tidy] Fix insertion location for certain function pointers in `cppcoreguidelines-init-variables` (PR #162218)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 7 07:54:13 PDT 2025
================
@@ -148,3 +148,19 @@ namespace gh112089 {
}
} // namespace gh112089
+namespace gh161978 {
+ void test() {
+ bool (*fp1)(int);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp1' is not initialized [cppcoreguidelines-init-variables]
+ // CHECK-FIXES: bool (*fp1)(int) = nullptr;
+ bool (*fp2)(int, int);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp2' is not initialized [cppcoreguidelines-init-variables]
+ // CHECK-FIXES: bool (*fp2)(int, int) = nullptr;
+ bool (*fp3)(int, int, int);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp3' is not initialized [cppcoreguidelines-init-variables]
+ // CHECK-FIXES: bool (*fp3)(int, int, int) = nullptr;
+ bool (*fp4)(int, int, int, ...);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp4' is not initialized [cppcoreguidelines-init-variables]
+ // CHECK-FIXES: bool (*fp4)(int, int, int, ...) = nullptr;
+ }
----------------
localspook wrote:
I think it would be good to add a test like:
```cpp
bool (*fp5)(int, int), (*fp6)(int, int);
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'fp5' is not initialized [cppcoreguidelines-init-variables]
// CHECK-MESSAGES: :[[@LINE-2]]:26: warning: variable 'fp6' is not initialized [cppcoreguidelines-init-variables]
// CHECK-FIXES: bool (*fp5)(int, int) = nullptr, (*fp6)(int, int) = nullptr;
```
To ensure that we don't somehow confuse the comma in the parameter list with the comma separating the two variable declarations.
https://github.com/llvm/llvm-project/pull/162218
More information about the cfe-commits
mailing list