Handle the case where the base type is not dependent, but the derived one is.
Fixes pr13353.cpp.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160393 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index f2f7736..47b5625 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -40,6 +40,9 @@
   if (const PointerType *PTy = DerivedType->getAs<PointerType>())
     DerivedType = PTy->getPointeeType();
 
+  if (DerivedType->isDependentType())
+    return NULL;
+
   const RecordType *Ty = DerivedType->castAs<RecordType>();
   Decl *D = Ty->getDecl();
   return cast<CXXRecordDecl>(D);
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 915663e..177165c 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -10893,8 +10893,6 @@
   if (!MD)
     return;
   const Expr *Base = ME->getBase();
-  if (Base->getType()->isDependentType())
-    return;
   const CXXRecordDecl *MostDerivedClassDecl = Base->getBestDynamicClassType();
   if (!MostDerivedClassDecl)
     return;
diff --git a/test/SemaCXX/pr13353.cpp b/test/SemaCXX/pr13353.cpp
new file mode 100644
index 0000000..8fb5443
--- /dev/null
+++ b/test/SemaCXX/pr13353.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only  %s
+struct foo {
+  virtual void bar() ;
+};
+template<typename T>
+class zed : public foo {
+};
+template<typename T>
+class bah : public zed<T> {
+  void f() {
+     const_cast<foo *>(this->g())->bar();
+  }
+};