[cfe-commits] r140400 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaCXX/warn-weak-vtables.cpp

Douglas Gregor dgregor at apple.com
Fri Sep 23 12:04:04 PDT 2011


Author: dgregor
Date: Fri Sep 23 14:04:03 2011
New Revision: 140400

URL: http://llvm.org/viewvc/llvm-project?rev=140400&view=rev
Log:
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
<rdar://problem/9979458>. 

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/warn-weak-vtables.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=140400&r1=140399&r2=140400&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Sep 23 14:04:03 2011
@@ -10302,7 +10302,10 @@
     // 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;
     }
   }

Modified: cfe/trunk/test/SemaCXX/warn-weak-vtables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-weak-vtables.cpp?rev=140400&r1=140399&r2=140400&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-weak-vtables.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-weak-vtables.cpp Fri Sep 23 14:04:03 2011
@@ -29,3 +29,30 @@
   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();
+}





More information about the cfe-commits mailing list