From: Anders Carlsson Date: Mon, 7 Dec 2009 08:29:39 +0000 (+0000) Subject: Instantiated or specialized class templates never have a key function. This (and... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=863dbcb45eb7b1e663f2d62be0fbdda6d9aa13ef;p=clang 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 550a32b0d0..f7da890350 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/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/test/SemaTemplate/virtual-member-functions.cpp b/test/SemaTemplate/virtual-member-functions.cpp new file mode 100644 index 0000000000..486c8b2051 --- /dev/null +++ b/test/SemaTemplate/virtual-member-functions.cpp @@ -0,0 +1,22 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +namespace PR5557 { +template struct A { + A(); + virtual int a(T x); +}; +template A::A() {} +template int A::a(T x) { + return *x; // expected-error{{requires pointer operand}} +} + +A x; // expected-note{{instantiation}} + +template +struct X { + virtual void f(); +}; + +template<> +void X::f() { } +}