llvm / llvm-project

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

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

Open FalcoGer opened 10 months ago

FalcoGer commented 10 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 10 months ago

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

FalcoGer commented 10 months ago

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