Source code

Revision control

Other Tools

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/. */
4
5
#include "TrivialDtorChecker.h"
6
#include "CustomMatchers.h"
7
8
void TrivialDtorChecker::registerMatchers(MatchFinder *AstMatcher) {
9
AstMatcher->addMatcher(cxxRecordDecl(hasTrivialDtor()).bind("node"),
10
this);
11
}
12
13
void TrivialDtorChecker::check(const MatchFinder::MatchResult &Result) {
14
const char *Error = "class %0 must have a trivial destructor";
15
const CXXRecordDecl *Node = Result.Nodes.getNodeAs<CXXRecordDecl>("node");
16
17
if (!Node->hasDefinition()) {
18
return;
19
}
20
21
bool BadDtor = !Node->hasTrivialDestructor();
22
if (BadDtor)
23
diag(Node->getBeginLoc(), Error, DiagnosticIDs::Error) << Node;
24
}