CXXMethodDecl::isVirtual needs to check the canonical declaration. Fixes PR4878.

llvm-svn: 81715
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index 7fdb820..4d7c674 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -776,8 +776,13 @@
   bool isInstance() const { return !isStatic(); }
 
   bool isVirtual() const {
-    return isVirtualAsWritten() ||
-      (begin_overridden_methods() != end_overridden_methods());
+    CXXMethodDecl *CD = 
+      cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
+
+    if (CD->isVirtualAsWritten())
+      return true;
+    
+    return (CD->begin_overridden_methods() != CD->end_overridden_methods());
   }
   
   ///
diff --git a/clang/test/SemaCXX/attr-deprecated.cpp b/clang/test/SemaCXX/attr-deprecated.cpp
index c1bdfcc..54f8b5b 100644
--- a/clang/test/SemaCXX/attr-deprecated.cpp
+++ b/clang/test/SemaCXX/attr-deprecated.cpp
@@ -54,3 +54,13 @@
   c->C::f();
   c->B::f(); // expected-warning{{'f' is deprecated}}
 }
+
+struct D {
+  virtual void f() __attribute__((deprecated));
+};
+
+void D::f() { }
+
+void f(D* d) {
+  d->f();
+}