This revision was automatically updated to reflect the committed changes. Closed by commit rL282625: [clang-tidy] fix false-positive for cppcoreguidelines-pro-type-member-init… (authored by mgehre).
Changed prior to commit: https://reviews.llvm.org/D24848?vs=72677&id=72885#toc Repository: rL LLVM https://reviews.llvm.org/D24848 Files: clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp Index: clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp +++ clang-tools-extra/trunk/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; } Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp +++ clang-tools-extra/trunk/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-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp +++ clang-tools-extra/trunk/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; } Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp +++ clang-tools-extra/trunk/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; +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits