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 "NonMemMovableMemberChecker.h"
6
#include "CustomMatchers.h"
7
8
MemMoveAnnotation NonMemMovable = MemMoveAnnotation();
9
10
void NonMemMovableMemberChecker::registerMatchers(MatchFinder *AstMatcher) {
11
// Handle non-mem-movable members
12
AstMatcher->addMatcher(cxxRecordDecl(needsMemMovableMembers()).bind("decl"),
13
this);
14
}
15
16
void NonMemMovableMemberChecker::check(const MatchFinder::MatchResult &Result) {
17
const char *Error =
18
"class %0 cannot have non-memmovable member %1 of type %2";
19
20
// Get the specialization
21
const CXXRecordDecl *Declaration =
22
Result.Nodes.getNodeAs<CXXRecordDecl>("decl");
23
24
// Report an error for every member which is non-memmovable
25
for (const FieldDecl *Field : Declaration->fields()) {
26
QualType Type = Field->getType();
27
if (NonMemMovable.hasEffectiveAnnotation(Type)) {
28
diag(Field->getLocation(), Error, DiagnosticIDs::Error)
29
<< Declaration << Field << Type;
30
NonMemMovable.dumpAnnotationReason(*this, Type,
31
Declaration->getLocation());
32
}
33
}
34
}