llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.87k stars 11.93k forks source link

[FR] Add option for clang-tidy check "cppcoreguidelines-init-variables" to use initializer lists #71583

Open FalcoGer opened 12 months ago

FalcoGer commented 12 months ago

I'd like an option for clang tidy's cppcoreguidelines-init-variables checker that provides fixes with an initializer list when possible.

Example:

int main()
{
  // int var;
  //     ~~~
  //     ^ Variable 'var' is not initialized (fix available) (clang-tidy cppcoreguidelines-init-variables)
  // Current fix:
  // int var = 0;
  // Desired fix:
  int var{};
  // alternatively (maybe another setting for that extra option?)
  // int var{0};
}
PiotrZSL commented 12 months ago

Only integers or all ? Currently: bool = false int = 0 pointer -= nullptr float = NAN

FalcoGer commented 12 months ago

Any. Also why are floats initialized to NAN? float f{}; makes it 0.F.