diff --git include/clang/AST/RecursiveASTVisitor.h include/clang/AST/RecursiveASTVisitor.h
index 46585d6..4a0176c 100644
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -1511,10 +1511,11 @@ DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
 
 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
     // D is the "T" in something like "template<typename T> class vector;"
-    if (D->getTypeForDecl())
-      TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
     if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
       TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
+    // We shouldn't traverse D->getTypeForDecl(); it's a result of
+    // declaring the template parameter, not something that was written
+    // in the source.
   })
 
 DEF_TRAVERSE_DECL(TypedefDecl, {
@@ -1546,10 +1547,10 @@ DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
   })
 
 DEF_TRAVERSE_DECL(EnumDecl, {
-    if (D->getTypeForDecl())
-      TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
-
     TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
+    // We shouldn't traverse D->getTypeForDecl(); it's a result of
+    // declaring the enum, not something that was written in the
+    // source.
     // The enumerators are already traversed by
     // decls_begin()/decls_end().
   })
diff --git unittests/Tooling/RecursiveASTVisitorTest.cpp unittests/Tooling/RecursiveASTVisitorTest.cpp
index a68a869..03b339c 100644
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -11,6 +11,14 @@
 
 namespace clang {
 
+class TypeVisitor : public ExpectedLocationVisitor<TypeVisitor> {
+public:
+  bool VisitType(Type *T) {
+    Match(QualType(T, Qualifiers()).getAsString(), SourceLocation());
+    return true;
+  }
+};
+
 class TypeLocVisitor : public ExpectedLocationVisitor<TypeLocVisitor> {
 public:
   bool VisitTypeLoc(TypeLoc TypeLocation) {
@@ -460,4 +468,16 @@ TEST(RecursiveASTVisitor, VisitsCompoundLiteralType) {
       TypeLocVisitor::Lang_C));
 }
 
+TEST(RecursiveASTVisitor, DisallowEnumDeclType) {
+  TypeVisitor Visitor;
+  Visitor.DisallowMatch("enum X", 0, 0);
+  EXPECT_TRUE(Visitor.runOver("enum X;", TypeVisitor::Lang_C));
+}
+
+TEST(RecursiveASTVisitor, DisallowTemplateTypeParmDeclType) {
+  TypeVisitor Visitor;
+  Visitor.DisallowMatch("T", 0, 0);
+  EXPECT_TRUE(Visitor.runOver("template<class T> class X;"));
+}
+
 } // end namespace clang
diff --git unittests/Tooling/TestVisitor.h unittests/Tooling/TestVisitor.h
index 8333c24..ade6d9e 100644
--- unittests/Tooling/TestVisitor.h
+++ unittests/Tooling/TestVisitor.h
@@ -170,9 +170,11 @@ protected:
     }
 
     bool MatchesLocation(FullSourceLoc const &Location) const {
-      return Location.isValid() &&
-          Location.getSpellingLineNumber() == LineNumber &&
-          Location.getSpellingColumnNumber() == ColumnNumber;
+      if (!Location.isValid())
+        return LineNumber == 0 && ColumnNumber == 0;
+
+      return LineNumber == Location.getSpellingLineNumber() &&
+             ColumnNumber == Location.getSpellingColumnNumber();
     }
 
     friend std::ostream &operator<<(std::ostream &Stream,
