]> granicus.if.org Git - clang/commitdiff
When checking for weak vtables, check whether the actual definition of
authorDouglas Gregor <dgregor@apple.com>
Fri, 23 Sep 2011 19:04:03 +0000 (19:04 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 23 Sep 2011 19:04:03 +0000 (19:04 +0000)
the key function is inline, rather than the original
declaration. Perhaps FunctionDecl::isInlined() is poorly named. Fixes
<rdar://problem/9979458>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140400 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/warn-weak-vtables.cpp

index ef8719c48e5d6f14fbc862454386b92a152e80a4..0727bbd36c6f5cd3c123c1fc0ef86a44386920a5 100644 (file)
@@ -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;
     }
   }
index c0cfd74a3e528665675703c33203043433f51977..912622f5a7e4391f07c73824fd55c09aadb58f98 100644 (file)
@@ -29,3 +29,30 @@ void uses(A &a, B<int> &b, C &c) {
   b.f();
   c.f();
 }
+
+// <rdar://problem/9979458>
+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();
+}