]> granicus.if.org Git - clang/commitdiff
Instantiated or specialized class templates never have a key function. This (and...
authorAnders Carlsson <andersca@mac.com>
Mon, 7 Dec 2009 08:29:39 +0000 (08:29 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 7 Dec 2009 08:29:39 +0000 (08:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90753 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/RecordLayoutBuilder.cpp
test/SemaTemplate/virtual-member-functions.cpp [new file with mode: 0644]

index 550a32b0d0513a09620ed9136bafe950f03c8798..f7da8903504eac74bd5a1f7642f05688168ce59f 100644 (file)
@@ -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/test/SemaTemplate/virtual-member-functions.cpp b/test/SemaTemplate/virtual-member-functions.cpp
new file mode 100644 (file)
index 0000000..486c8b2
--- /dev/null
@@ -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() { }
+}