diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-01 17:35:23 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-01 17:35:23 +0000 |
commit | e6342c06356976508525145a6ba433d05f893171 (patch) | |
tree | 39c5da0557deb504641da6063a60e498dd69ef79 | |
parent | 4ba3136b3eb9740a07bd61d0ab23ce9a8d894dee (diff) |
Funtion templates and function template specializations do not
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
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 | ||||
-rw-r--r-- | test/SemaCXX/virtual-override.cpp | 16 |
3 files changed, 19 insertions, 6 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 49be340873..5d62ace907 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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() && diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 615c6f9456..8808bf72db 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -870,8 +870,6 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, !Method->getFriendObjectKind()) Owner->addDecl(Method); - SemaRef.AddOverriddenMethods(Record, Method); - return Method; } diff --git a/test/SemaCXX/virtual-override.cpp b/test/SemaCXX/virtual-override.cpp index 6024dae838..cee64568cd 100644 --- a/test/SemaCXX/virtual-override.cpp +++ b/test/SemaCXX/virtual-override.cpp @@ -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); +}; |