Issue 61454
Summary clang-tidy feature request: C++ Core Guidelines "ES.23: Prefer the `{}`-initializer syntax" (avoid `()` initialization)
Labels new issue
Assignees
Reporter N-Dekker
    C++ Core Guidelines, September 23, 2022, item [ES.23: Prefer the `{}`-initializer syntax](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-list) says:

> Prefer {}. The rules for {} initialization are simpler, more general, less ambiguous, and safer than for other forms of initialization.
> 
> Use = only when you are sure that there can be no narrowing conversions. For built-in arithmetic types, use = only with auto.
>
> Avoid () initialization, which allows parsing ambiguities.

So for example, when declaring an `m` x `n` matrix object (assuming a `Matrix::Matrix(int m, int n)` constructor):

    Matrix oldStyleMatrix(m, n);  // Old style: initialization using parentheses
 Matrix newStyleMatrix{m, n};  // New style: initialization using curly braces.

The new style (using curly braces) appears preferable, according to this guideline. Would it be possible to add a clang-tidy check, to warn against using the old style, as well as the ability to convert code to the new style (using the option `-fix`)?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to