Instantiated or specialized class templates never have a key function. This (and the previous check-in) fixes PR5557.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90753 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp
index 550a32b..f7da890 100644
--- a/lib/AST/RecordLayoutBuilder.cpp
+++ b/lib/AST/RecordLayoutBuilder.cpp
@@ -720,6 +720,11 @@
if (!RD->isPolymorphic())
return 0;
+ // A class template specialization or instantation does not have a key
+ // function.
+ if (RD->getTemplateSpecializationKind() != TSK_Undeclared)
+ return 0;
+
for (CXXRecordDecl::method_iterator I = RD->method_begin(),
E = RD->method_end(); I != E; ++I) {
const CXXMethodDecl *MD = *I;
diff --git a/test/SemaTemplate/virtual-member-functions.cpp b/test/SemaTemplate/virtual-member-functions.cpp
new file mode 100644
index 0000000..486c8b2
--- /dev/null
+++ b/test/SemaTemplate/virtual-member-functions.cpp
@@ -0,0 +1,22 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+namespace PR5557 {
+template <class T> struct A {
+ A();
+ virtual int a(T x);
+};
+template<class T> A<T>::A() {}
+template<class T> int A<T>::a(T x) {
+ return *x; // expected-error{{requires pointer operand}}
+}
+
+A<int> x; // expected-note{{instantiation}}
+
+template<typename T>
+struct X {
+ virtual void f();
+};
+
+template<>
+void X<int>::f() { }
+}