Skip to content

clang-tidy: cppcoreguidelines-init-variables does not work for a function pointer that has two or more parameters #161978

@e-kwsm

Description

@e-kwsm
int main() {
  bool (*fp1)(int);
  bool (*fp2)(int, int);
}
$ clang-tidy '--checks=-*,cppcoreguidelines-init-variables' --fix a.cpp
/tmp/a.cpp:2:10: warning: variable 'fp1' is not initialized [cppcoreguidelines-init-variables]
    2 |   bool (*fp1)(int);
      |          ^
      |                    = nullptr
/tmp/a.cpp:2:19: note: FIX-IT applied suggested code changes
    2 |   bool (*fp1)(int);
      |                   ^
/tmp/a.cpp:3:10: warning: variable 'fp2' is not initialized [cppcoreguidelines-init-variables]
    3 |   bool (*fp2)(int, int);
      |          ^
      |                   = nullptr
/tmp/a.cpp:3:18: note: FIX-IT applied suggested code changes
    3 |   bool (*fp2)(int, int);
      |                  ^
clang-tidy applied 2 of 2 suggested fixes.

gives

int main() {
  bool (*fp1)(int) = nullptr;
  bool (*fp2)(int = nullptr, int);
}

https://godbolt.org/z/hTjdh79K5

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-tidyinvalid-code-generationTool (e.g. clang-format) produced invalid code that no longer compiles

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions