Bug 1642744 [wpt PR 23920] - [ScrollTimeline] Update compositor timeline from blink...
[gecko.git] / build / clang-plugin / RefCountedCopyConstructorChecker.cpp
blob569d4eecec75725cfefd731e5919ef5cd0663429
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(
11 cxxConstructExpr(
12 hasDeclaration(cxxConstructorDecl(isCompilerProvidedCopyConstructor(),
13 ofClass(hasRefCntMember()))))
14 .bind("node"),
15 this);
18 void RefCountedCopyConstructorChecker::check(
19 const MatchFinder::MatchResult &Result) {
20 const char *Error =
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 "
26 "need to be copied";
28 // Everything we needed to know was checked in the matcher - we just report
29 // the error here
30 const CXXConstructExpr *E = Result.Nodes.getNodeAs<CXXConstructExpr>("node");
32 diag(E->getLocation(), Error, DiagnosticIDs::Error);
33 diag(E->getLocation(), Note, DiagnosticIDs::Note);