[cfe-commits] r90242 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaCXX/virtual-override.cpp
Douglas Gregor
dgregor at apple.com
Tue Dec 1 09:35:24 PST 2009
Author: dgregor
Date: Tue Dec 1 11:35:23 2009
New Revision: 90242
URL: http://llvm.org/viewvc/llvm-project?rev=90242&view=rev
Log:
Funtion templates and function template specializations do not
override virtual functions. Also, eliminate a (now redundant) call to
AddOverriddenMethods.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaCXX/virtual-override.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=90242&r1=90241&r2=90242&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Dec 1 11:35:23 2009
@@ -3259,8 +3259,11 @@
}
// 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() &&
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=90242&r1=90241&r2=90242&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Dec 1 11:35:23 2009
@@ -870,8 +870,6 @@
!Method->getFriendObjectKind())
Owner->addDecl(Method);
- SemaRef.AddOverriddenMethods(Record, Method);
-
return Method;
}
Modified: cfe/trunk/test/SemaCXX/virtual-override.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/virtual-override.cpp?rev=90242&r1=90241&r2=90242&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/virtual-override.cpp (original)
+++ cfe/trunk/test/SemaCXX/virtual-override.cpp Tue Dec 1 11:35:23 2009
@@ -115,13 +115,25 @@
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);
+};
More information about the cfe-commits
mailing list