Check that the function being overridden is virtual.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71802 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index 45af36c..865dd97 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -149,7 +149,7 @@
   FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
   FD->setInline(Record[Idx++]);
   FD->setC99InlineDefinition(Record[Idx++]);
-  FD->setVirtual(Record[Idx++]);
+  FD->setVirtualAsWritten(Record[Idx++]);
   FD->setPure(Record[Idx++]);
   FD->setHasInheritedPrototype(Record[Idx++]);
   FD->setHasWrittenPrototype(Record[Idx++]);
diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp
index 48c7dc2..5d08334 100644
--- a/lib/Frontend/PCHWriterDecl.cpp
+++ b/lib/Frontend/PCHWriterDecl.cpp
@@ -149,7 +149,7 @@
   Record.push_back(D->getStorageClass()); // FIXME: stable encoding
   Record.push_back(D->isInline());
   Record.push_back(D->isC99InlineDefinition());
-  Record.push_back(D->isVirtual());
+  Record.push_back(D->isVirtualAsWritten());
   Record.push_back(D->isPure());
   Record.push_back(D->hasInheritedPrototype());
   Record.push_back(D->hasWrittenPrototype());
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 1c464d1..feb9595 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2125,7 +2125,7 @@
                              SourceRange(D.getDeclSpec().getVirtualSpecLoc()));
     } else {
       // Okay: Add virtual to the method.
-      cast<CXXMethodDecl>(NewFD)->setVirtual();
+      cast<CXXMethodDecl>(NewFD)->setVirtualAsWritten(true);
       CXXRecordDecl *CurClass = cast<CXXRecordDecl>(DC);
       CurClass->setAggregate(false);
       CurClass->setPOD(false);
@@ -2152,6 +2152,8 @@
           // FIXME: Is this OK? Should it be done by LookupInBases?
           if (IsOverload(NewMD, OldMD, MatchedDecl))
             continue;
+          if (!OldMD->isVirtual())
+            continue;
          
           if (!CheckOverridingFunctionReturnType(NewMD, OldMD)) {
             // FIXME: Add OldMD to the list of methods NewMD overrides.
@@ -2490,7 +2492,7 @@
     Expr *Init = static_cast<Expr *>(init.get());
     if ((IL = dyn_cast<IntegerLiteral>(Init)) && IL->getValue() == 0 &&
         Context.getCanonicalType(IL->getType()) == Context.IntTy) {
-      if (Method->isVirtual()) {
+      if (Method->isVirtualAsWritten()) {
         Method->setPure();
 
         // A class is abstract if at least one function is pure virtual.
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 19aaafb..02df593 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -546,8 +546,8 @@
                                                   CXXMethodDecl *Tmpl) {
   CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner);
   New->setAccess(Tmpl->getAccess());
-  if (Tmpl->isVirtual()) {
-    New->setVirtual();
+  if (Tmpl->isVirtualAsWritten()) {
+    New->setVirtualAsWritten(true);
     Record->setAggregate(false);
     Record->setPOD(false);
     Record->setPolymorphic(true);