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 "NonMemMovableTemplateArgChecker.h"
6 #include "CustomMatchers.h"
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"),
19 void NonMemMovableTemplateArgChecker::check(
20 const MatchFinder::MatchResult
&Result
) {
22 "Cannot instantiate %0 with non-memmovable template argument %1";
23 const char *Note
= "instantiation of %0 requested here";
25 // Get the specialization
26 const ClassTemplateSpecializationDecl
*Specialization
=
27 Result
.Nodes
.getNodeAs
<ClassTemplateSpecializationDecl
>("specialization");
28 SourceLocation RequestLoc
= Specialization
->getPointOfInstantiation();
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
40 // from Sema such that we could print a full template instantiation stack,
42 // it seems as though that information is thrown out by the time we get
44 // can only report one level of template specialization (which in many
47 diag(RequestLoc
, Note
, DiagnosticIDs::Note
) << Specialization
;
48 NonMemMovable
.dumpAnnotationReason(*this, ArgType
, RequestLoc
);