From: Douglas Gregor Date: Tue, 1 Dec 2009 17:35:23 +0000 (+0000) Subject: Funtion templates and function template specializations do not X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6342c06356976508525145a6ba433d05f893171;p=clang 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 --- 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(NewFD)) - AddOverriddenMethods(Method->getParent(), Method); + if (CXXMethodDecl *Method = dyn_cast(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 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 f1; Foo f2; // expected-note{{instantiation}} } + +template +struct Foo2 : Base { + template int f(T); +}; + +void test2() { + Foo2 f1; + Foo2 f2; + f1.f(17); + f2.f(17); +};