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 "NonMemMovableMemberChecker.h"
6 #include "CustomMatchers.h"
8 MemMoveAnnotation NonMemMovable
= MemMoveAnnotation();
10 void NonMemMovableMemberChecker::registerMatchers(MatchFinder
*AstMatcher
) {
11 // Handle non-mem-movable members
12 AstMatcher
->addMatcher(cxxRecordDecl(needsMemMovableMembers()).bind("decl"),
16 void NonMemMovableMemberChecker::check(const MatchFinder::MatchResult
&Result
) {
18 "class %0 cannot have non-memmovable member %1 of type %2";
20 // Get the specialization
21 const CXXRecordDecl
*Declaration
=
22 Result
.Nodes
.getNodeAs
<CXXRecordDecl
>("decl");
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());