Sema: Don't crash when an inject class name has a nested redefinition

We expected the type of a TagDecl to be a TagType, not an
InjectedClassNameType.  Introduced a helper method, Type::getAsTagDecl,
to abstract away the difference; redefine Type::getAsCXXRecordDecl to be
in terms of it.

llvm-svn: 224898
diff --git a/clang/test/SemaCXX/struct-class-redecl.cpp b/clang/test/SemaCXX/struct-class-redecl.cpp
index e1b95ba..706ec56 100644
--- a/clang/test/SemaCXX/struct-class-redecl.cpp
+++ b/clang/test/SemaCXX/struct-class-redecl.cpp
@@ -7,6 +7,12 @@
 template<typename T> struct Y; // expected-note{{did you mean class here?}}
 template<class U> class Y { }; // expected-warning{{previously declared}}
 
+template <typename>
+struct Z {   // expected-note{{previous definition is here}}
+  struct Z { // expected-error{{nested redefinition of 'Z'}}
+  };
+};
+
 class A;
 class A;  // expected-note{{previous use is here}}
 struct A;  // expected-warning{{struct 'A' was previously declared as a class}}