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 "NonMemMovableTemplateArgChecker.h"
6
#include "CustomMatchers.h"
7
8
void NonMemMovableTemplateArgChecker::registerMatchers(
9
MatchFinder *AstMatcher) {
10
// Handle non-mem-movable template specializations
11
AstMatcher->addMatcher(
12
classTemplateSpecializationDecl(
13
allOf(needsMemMovableTemplateArg(),
14
hasAnyTemplateArgument(refersToType(isNonMemMovable()))))
15
.bind("specialization"),
16
this);
17
}
18
19
void NonMemMovableTemplateArgChecker::check(
20
const MatchFinder::MatchResult &Result) {
21
const char *Error =
22
"Cannot instantiate %0 with non-memmovable template argument %1";
23
const char *Note = "instantiation of %0 requested here";
24
25
// Get the specialization
26
const ClassTemplateSpecializationDecl *Specialization =
27
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("specialization");
28
SourceLocation RequestLoc = Specialization->getPointOfInstantiation();
29
30
// Report an error for every template argument which is non-memmovable
31
const TemplateArgumentList &Args =
32
Specialization->getTemplateInstantiationArgs();
33
for (unsigned i = 0; i < Args.size(); ++i) {
34
QualType ArgType = Args[i].getAsType();
35
if (NonMemMovable.hasEffectiveAnnotation(ArgType)) {
36
diag(Specialization->getLocation(), Error, DiagnosticIDs::Error)
37
<< Specialization << ArgType;
38
// XXX It would be really nice if we could get the instantiation stack
39
// information
40
// from Sema such that we could print a full template instantiation stack,
41
// however,
42
// it seems as though that information is thrown out by the time we get
43
// here so we
44
// can only report one level of template specialization (which in many
45
// cases won't
46
// be useful)
47
diag(RequestLoc, Note, DiagnosticIDs::Note) << Specialization;
48
NonMemMovable.dumpAnnotationReason(*this, ArgType, RequestLoc);
49
}
50
}
51
}