1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "RefCountedCopyConstructorChecker.h"
6 #include "CustomMatchers.h"
8 void RefCountedCopyConstructorChecker::registerMatchers(
9 MatchFinder
*AstMatcher
) {
10 AstMatcher
->addMatcher(
12 hasDeclaration(cxxConstructorDecl(isCompilerProvidedCopyConstructor(),
13 ofClass(hasRefCntMember()))))
18 void RefCountedCopyConstructorChecker::check(
19 const MatchFinder::MatchResult
&Result
) {
21 "Invalid use of compiler-provided copy constructor on refcounted type";
22 const char *Note
= "The default copy constructor also copies the "
23 "default mRefCnt property, leading to reference "
24 "count imbalance issues. Please provide your own "
25 "copy constructor which only copies the fields which "
28 // Everything we needed to know was checked in the matcher - we just report
30 const CXXConstructExpr
*E
= Result
.Nodes
.getNodeAs
<CXXConstructExpr
>("node");
32 diag(E
->getLocation(), Error
, DiagnosticIDs::Error
);
33 diag(E
->getLocation(), Note
, DiagnosticIDs::Note
);