From 34bc6e5ee401508a24cddd827c53b514dceb2347 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 23 Sep 2011 19:04:03 +0000 Subject: When checking for weak vtables, check whether the actual definition of the key function is inline, rather than the original declaration. Perhaps FunctionDecl::isInlined() is poorly named. Fixes . llvm-svn: 140400 --- clang/lib/Sema/SemaDeclCXX.cpp | 5 ++++- clang/test/SemaCXX/warn-weak-vtables.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'clang') diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index ef8719c48e5..0727bbd36c6 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -10302,7 +10302,10 @@ bool Sema::DefineUsedVTables() { // Optionally warn if we're emitting a weak vtable. if (Class->getLinkage() == ExternalLinkage && Class->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) { - if (!KeyFunction || (KeyFunction->hasBody() && KeyFunction->isInlined())) + const FunctionDecl *KeyFunctionDef = 0; + if (!KeyFunction || + (KeyFunction->hasBody(KeyFunctionDef) && + KeyFunctionDef->isInlined())) Diag(Class->getLocation(), diag::warn_weak_vtable) << Class; } } diff --git a/clang/test/SemaCXX/warn-weak-vtables.cpp b/clang/test/SemaCXX/warn-weak-vtables.cpp index c0cfd74a3e5..912622f5a7e 100644 --- a/clang/test/SemaCXX/warn-weak-vtables.cpp +++ b/clang/test/SemaCXX/warn-weak-vtables.cpp @@ -29,3 +29,30 @@ void uses(A &a, B &b, C &c) { b.f(); c.f(); } + +// +class Parent { +public: + Parent() {} + virtual ~Parent(); + virtual void * getFoo() const = 0; +}; + +class Derived : public Parent { +public: + Derived(); + void * getFoo() const; +}; + +class VeryDerived : public Derived { // expected-warning{{'VeryDerived' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}} +public: + void * getFoo() const { return 0; } +}; + +Parent::~Parent() {} + +void uses(Parent &p, Derived &d, VeryDerived &vd) { + p.getFoo(); + d.getFoo(); + vd.getFoo(); +} -- cgit v1.2.3