[PATCH] D24892: [clang-tidy] Add option "LiteralInitializers" to cppcoreguidelines-pro-type-member-init

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 25 15:15:11 PDT 2017


aaron.ballman added inline comments.


================
Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:377
+        else if (type->isIntegerType())
+          Initializer = " = 0";
+        else if (type->isFloatingType())
----------------
mgehre wrote:
> aaron.ballman wrote:
> > What about cases where a suffix is desired, like `U` or `LL`?
> Is this really necessary for initializing to zero?
> The compiler will figure out the correct thing, and I personally find "0" easier to read than "0ULL".
It is necessary because of the way literals are typed. [lex.icon]p2 lists what happens when there is no suffix on a literal, but it boils down to the compiler picking the first type that can represent the value, out of int, long int, or long long int. Without the U or the LL, the type of the literal will not match the type of the field. This shouldn't have an impact on the generated code, but it may cause diagnostics for some compilers.


https://reviews.llvm.org/D24892





More information about the cfe-commits mailing list