hokein created this revision. hokein added a reviewer: aaron.ballman. hokein added a subscriber: cfe-commits. Herald added a subscriber: nemanjai.
The matcher for matching "class with default constructor" still match some classes without default constructor, which trigger an assert at Line 307. This patch makes the matcher more strict. https://reviews.llvm.org/D25747 Files: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.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 @@ -450,3 +450,9 @@ NegativeIncompleteArrayMember() {} char e[]; }; + +template <typename T> class NoCrash { + class B : public NoCrash { + template <typename U> B(U u) {} + }; +}; Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp =================================================================== --- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -27,6 +27,10 @@ namespace { +AST_MATCHER(CXXRecordDecl, hasDefaultConstructor) { + return Node.hasDefaultConstructor(); +} + // Iterate over all the fields in a record type, both direct and indirect (e.g. // if the record contains an anonmyous struct). If OneFieldPerUnion is true and // the record type (or indirect field) is a union, forEachField will stop after @@ -275,6 +279,7 @@ Finder->addMatcher( cxxRecordDecl( isDefinition(), unless(isInstantiated()), + hasDefaultConstructor(), anyOf(has(cxxConstructorDecl(isDefaultConstructor(), isDefaulted(), unless(isImplicit()))), unless(has(cxxConstructorDecl()))),
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 @@ -450,3 +450,9 @@ NegativeIncompleteArrayMember() {} char e[]; }; + +template <typename T> class NoCrash { + class B : public NoCrash { + template <typename U> B(U u) {} + }; +}; Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp =================================================================== --- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -27,6 +27,10 @@ namespace { +AST_MATCHER(CXXRecordDecl, hasDefaultConstructor) { + return Node.hasDefaultConstructor(); +} + // Iterate over all the fields in a record type, both direct and indirect (e.g. // if the record contains an anonmyous struct). If OneFieldPerUnion is true and // the record type (or indirect field) is a union, forEachField will stop after @@ -275,6 +279,7 @@ Finder->addMatcher( cxxRecordDecl( isDefinition(), unless(isInstantiated()), + hasDefaultConstructor(), anyOf(has(cxxConstructorDecl(isDefaultConstructor(), isDefaulted(), unless(isImplicit()))), unless(has(cxxConstructorDecl()))),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits