Skip to content

[clang-tidy] when try to use code action to fix the function pointer not initialized problem, clang-tidy add =nullptr to the wrong place #112089

Closed
@LXYan2333

Description

@LXYan2333

code example:

int main() {
    void(*f)(void*);
}

the function pointer f is not initialized, and clang-tidy suggest to add =nullptr to initialize it. but clang-tidy add it to a wrong position:

code example from @HighCommander4

$ cat test.cpp
int main() {
    void(*f)(void*);
}

$ clang-tidy --checks=cppcoreguidelines-init-variables --fix test.cpp
Running without flags.
1 warning generated.
test.cpp:2:11: warning: variable 'f' is not initialized [cppcoreguidelines-init-variables]
    2 |     void(*f)(void*);
      |           ^
      |             = nullptr
test.cpp:2:12: note: FIX-IT applied suggested code changes
    2 |     void(*f)(void*);
      |            ^
clang-tidy applied 1 of 1 suggested fixes.

$ cat test.cpp
int main() {
    void(*f = nullptr)(void*);
}

expected behaviour:

int main() {
    void(*f)(void*)=nullptr;
}

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorclang-tidy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions