[PATCH] D24848: [clang-tidy] fix false-positive for cppcoreguidelines-pro-type-member-init with in-class initializers
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 27 11:08:24 PDT 2016
On Tue, Sep 27, 2016 at 2:05 PM, Matthias Gehre <M.Gehre at gmx.de> wrote:
> mgehre updated this revision to Diff 72677.
> mgehre added a comment.
>
> Rename the struct that was introduced in the test. Note that I need to keep the function Bug30487,
> because that is where the false-positive warning was emitted.
We usually use namespaces for this when working with C++ code, where
the namespace identifier is pr30487 (e.g.).
~Aaron
>
>
> https://reviews.llvm.org/D24848
>
> Files:
> clang-tidy/utils/TypeTraits.cpp
> test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
>
> Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
> ===================================================================
> --- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
> +++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
> @@ -73,6 +73,11 @@
> NegativeInClassInitialized() {}
> };
>
> +struct NegativeInClassInitializedDefaulted {
> + int F = 0;
> + NegativeInClassInitializedDefaulted() = default;
> +};
> +
> struct NegativeConstructorDelegated {
> int F;
>
> @@ -367,3 +372,8 @@
> PositiveIndirectMember() {}
> // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A
> };
> +
> +void Bug30487()
> +{
> + NegativeInClassInitializedDefaulted s;
> +}
> Index: clang-tidy/utils/TypeTraits.cpp
> ===================================================================
> --- clang-tidy/utils/TypeTraits.cpp
> +++ clang-tidy/utils/TypeTraits.cpp
> @@ -62,8 +62,10 @@
> if (ClassDecl->hasTrivialDefaultConstructor())
> return true;
>
> - // If all its fields are trivially constructible.
> + // If all its fields are trivially constructible and have no default initializers.
> for (const FieldDecl *Field : ClassDecl->fields()) {
> + if (Field->hasInClassInitializer())
> + return false;
> if (!isTriviallyDefaultConstructible(Field->getType(), Context))
> return false;
> }
>
>
More information about the cfe-commits
mailing list