]> granicus.if.org Git - clang/commitdiff
Funtion templates and function template specializations do not
authorDouglas Gregor <dgregor@apple.com>
Tue, 1 Dec 2009 17:35:23 +0000 (17:35 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 1 Dec 2009 17:35:23 +0000 (17:35 +0000)
override virtual functions. Also, eliminate a (now redundant) call to
AddOverriddenMethods.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90242 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaCXX/virtual-override.cpp

index 49be3408738d1dc3875092306b2e278003b31689..5d62ace9070222fc07a4b6902b38e2e823b7a5de 100644 (file)
@@ -3259,8 +3259,11 @@ void Sema::CheckFunctionDeclaration(FunctionDecl *NewFD,
     }
 
     // Find any virtual functions that this function overrides.
-    if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(NewFD))
-      AddOverriddenMethods(Method->getParent(), Method);
+    if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(NewFD)) {
+      if (!Method->isFunctionTemplateSpecialization() && 
+          !Method->getDescribedFunctionTemplate())
+        AddOverriddenMethods(Method->getParent(), Method);
+    }
 
     // Extra checking for C++ overloaded operators (C++ [over.oper]).
     if (NewFD->isOverloadedOperator() &&
index 615c6f9456757ed19c6eae818b53437f9feec258..8808bf72db5187e3c31d851a69a6ccee0e6b0772 100644 (file)
@@ -870,8 +870,6 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D,
       !Method->getFriendObjectKind())
     Owner->addDecl(Method);
 
-  SemaRef.AddOverriddenMethods(Record, Method);
-
   return Method;
 }
 
index 6024dae8386938b22a7ff7a995a72a1b09b5ce9c..cee64568cd895da49f11f4e8f7a6d0ccde7ef4e8 100644 (file)
@@ -115,13 +115,25 @@ class X1 : public X0 {
 
 template <typename Base>
 struct Foo : Base { 
-  void f() = 0; // expected-error{{not virtual and cannot be declared pure}}
+  void f(int) = 0; // expected-error{{not virtual and cannot be declared pure}}
 };
 
-struct Base1 { virtual void f(); };
+struct Base1 { virtual void f(int); };
 struct Base2 { };
 
 void test() {
   Foo<Base1> f1;
   Foo<Base2> f2; // expected-note{{instantiation}}
 }
+
+template<typename Base>
+struct Foo2 : Base {
+  template<typename T> int f(T);
+};
+
+void test2() {
+  Foo2<Base1> f1;
+  Foo2<Base2> f2;
+  f1.f(17);
+  f2.f(17);
+};