[clang-tools-extra] r284727 - [clang-tidy] Fix an assertion failure in cppcoreguidelines-pro-type-member-init.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 20 06:15:40 PDT 2016


Author: hokein
Date: Thu Oct 20 08:15:40 2016
New Revision: 284727

URL: http://llvm.org/viewvc/llvm-project?rev=284727&view=rev
Log:
[clang-tidy] Fix an assertion failure in cppcoreguidelines-pro-type-member-init.

Summary:
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.

Reviewers: aaron.ballman

Subscribers: nemanjai, cfe-commits

Differential Revision: https://reviews.llvm.org/D25747

Modified:
    clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp?rev=284727&r1=284726&r2=284727&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp Thu Oct 20 08:15:40 2016
@@ -27,6 +27,10 @@ namespace cppcoreguidelines {
 
 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 @@ void ProTypeMemberInitCheck::registerMat
   Finder->addMatcher(
       cxxRecordDecl(
           isDefinition(), unless(isInstantiated()),
+          hasDefaultConstructor(),
           anyOf(has(cxxConstructorDecl(isDefaultConstructor(), isDefaulted(),
                                        unless(isImplicit()))),
                 unless(has(cxxConstructorDecl()))),

Modified: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp?rev=284727&r1=284726&r2=284727&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp Thu Oct 20 08:15:40 2016
@@ -450,3 +450,9 @@ struct NegativeIncompleteArrayMember {
   NegativeIncompleteArrayMember() {}
   char e[];
 };
+
+template <typename T> class NoCrash {
+  class B : public NoCrash {
+    template <typename U> B(U u) {}
+  };
+};




More information about the cfe-commits mailing list