NoAutoTypeChecker.cpp (809B)
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 "NoAutoTypeChecker.h" 6 #include "CustomMatchers.h" 7 8 void NoAutoTypeChecker::registerMatchers(MatchFinder *AstMatcher) { 9 AstMatcher->addMatcher(varDecl(hasType(autoNonAutoableType())).bind("node"), 10 this); 11 } 12 13 void NoAutoTypeChecker::check(const MatchFinder::MatchResult &Result) { 14 const VarDecl *D = Result.Nodes.getNodeAs<VarDecl>("node"); 15 16 diag(D->getLocation(), "Cannot use auto to declare a variable of type %0", 17 DiagnosticIDs::Error) 18 << D->getType(); 19 diag(D->getLocation(), "Please write out this type explicitly", 20 DiagnosticIDs::Note); 21 }