summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/AST/RecordLayoutBuilder.cpp5
-rw-r--r--clang/test/SemaTemplate/virtual-member-functions.cpp22
2 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp
index 550a32b0d05..f7da8903504 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -720,6 +720,11 @@ ASTRecordLayoutBuilder::ComputeKeyFunction(const CXXRecordDecl *RD) {
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/clang/test/SemaTemplate/virtual-member-functions.cpp b/clang/test/SemaTemplate/virtual-member-functions.cpp
new file mode 100644
index 00000000000..486c8b20514
--- /dev/null
+++ b/clang/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() { }
+}
OpenPOWER on IntegriCloud