226 auto EmitValueWarning = [
this, &Result](
const NestedNameSpecifierLoc &QualLoc,
227 SourceLocation EndLoc) {
228 SourceLocation TemplateNameEndLoc;
230 QualLoc.getAsTypeLoc().getAs<TemplateSpecializationTypeLoc>())
231 TemplateNameEndLoc = Lexer::getLocForEndOfToken(
232 TSTL.getTemplateNameLoc(), 0, *Result.SourceManager,
233 Result.Context->getLangOpts());
237 if (EndLoc.isMacroID() || QualLoc.getEndLoc().isMacroID() ||
238 TemplateNameEndLoc.isMacroID()) {
241 diag(QualLoc.getBeginLoc(),
"use c++17 style variable templates");
244 diag(QualLoc.getBeginLoc(),
"use c++17 style variable templates")
245 << FixItHint::CreateInsertion(TemplateNameEndLoc,
"_v")
246 << FixItHint::CreateRemoval({QualLoc.getEndLoc(), EndLoc});
249 auto EmitTypeWarning = [
this, &Result](
const NestedNameSpecifierLoc &QualLoc,
250 SourceLocation EndLoc,
251 SourceLocation TypenameLoc) {
252 SourceLocation TemplateNameEndLoc;
254 QualLoc.getAsTypeLoc().getAs<TemplateSpecializationTypeLoc>())
255 TemplateNameEndLoc = Lexer::getLocForEndOfToken(
256 TSTL.getTemplateNameLoc(), 0, *Result.SourceManager,
257 Result.Context->getLangOpts());
261 if (EndLoc.isMacroID() || QualLoc.getEndLoc().isMacroID() ||
262 TemplateNameEndLoc.isMacroID() || TypenameLoc.isMacroID()) {
265 diag(QualLoc.getBeginLoc(),
"use c++14 style type templates");
268 auto Diag = diag(QualLoc.getBeginLoc(),
"use c++14 style type templates");
270 if (TypenameLoc.isValid())
271 Diag << FixItHint::CreateRemoval(TypenameLoc);
272 Diag << FixItHint::CreateInsertion(TemplateNameEndLoc,
"_t")
273 << FixItHint::CreateRemoval({QualLoc.getEndLoc(), EndLoc});
276 if (
const auto *DRE = Result.Nodes.getNodeAs<DeclRefExpr>(
Bind)) {
277 if (!DRE->hasQualifier())
279 if (
const auto *CTSD = dyn_cast_if_present<ClassTemplateSpecializationDecl>(
280 DRE->getQualifier().getAsRecordDecl())) {
282 EmitValueWarning(DRE->getQualifierLoc(), DRE->getEndLoc());
287 if (
const auto *TL = Result.Nodes.getNodeAs<TypedefTypeLoc>(
Bind)) {
288 const NestedNameSpecifierLoc QualLoc = TL->getQualifierLoc();
289 NestedNameSpecifier NNS = QualLoc.getNestedNameSpecifier();
290 if (
const auto *CTSD = dyn_cast_if_present<ClassTemplateSpecializationDecl>(
291 NNS.getAsRecordDecl())) {
293 EmitTypeWarning(TL->getQualifierLoc(), TL->getEndLoc(),
294 TL->getElaboratedKeywordLoc());
299 if (
const auto *DSDRE =
300 Result.Nodes.getNodeAs<DependentScopeDeclRefExpr>(
Bind)) {
302 EmitValueWarning(DSDRE->getQualifierLoc(), DSDRE->getEndLoc());
306 if (
const auto *DNTL = Result.Nodes.getNodeAs<DependentNameTypeLoc>(
Bind)) {
307 NestedNameSpecifierLoc QualLoc = DNTL->getQualifierLoc();
309 EmitTypeWarning(QualLoc, DNTL->getEndLoc(),
310 DNTL->getElaboratedKeywordLoc());
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.