[PATCH] D10935: [Sema] Don't emit "pure virtual" warning for fully qualified calls.

Davide Italiano dccitaliano at gmail.com
Mon Jul 6 12:44:44 PDT 2015


davide added a reviewer: thakis.
davide removed a subscriber: thakis.
davide removed rL LLVM as the repository for this revision.

Addressed Nico's comments. While at it added a test.
Nico, I hope this is the right way of checking.


http://reviews.llvm.org/D10935

Files:
  lib/Sema/SemaOverload.cpp
  test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp
  test/SemaCXX/warn-pure-virtual-kext.cpp

Index: test/SemaCXX/warn-pure-virtual-kext.cpp
===================================================================
--- test/SemaCXX/warn-pure-virtual-kext.cpp
+++ test/SemaCXX/warn-pure-virtual-kext.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -fapple-kext -fsyntax-only -verify
+
+struct A {
+    virtual void f() = 0; // expected-note {{'f' declared here}}
+    A() {
+        A::f(); // expected-warning {{call to pure virtual member function 'f'; overrides of 'f' in subclasses are not available in the constructor of 'A'}}
+    }
+};
Index: test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp
===================================================================
--- test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp
+++ test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp
@@ -12,3 +12,11 @@
   B() { a->f(); };
   ~B() { a->f(); };
 };
+
+// Don't warn if the call is fully qualified. (PR23215)
+struct C {
+    virtual void f() = 0;
+    C() {
+        C::f();
+    }
+};
Index: lib/Sema/SemaOverload.cpp
===================================================================
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -11788,8 +11788,13 @@
       TheCall->getMethodDecl()->isPure()) {
     const CXXMethodDecl *MD = TheCall->getMethodDecl();
 
-    if (isa<CXXThisExpr>(MemExpr->getBase()->IgnoreParenCasts())) {
-      Diag(MemExpr->getLocStart(), 
+    // If the member access is fully qualified, (i.e. X::f()), treat
+    // it as a non-virtual call and don't warn. In -fapple-kext mode
+    // qualified calls to virtual method will still go through the
+    // vtable so we don't want to skip the warning.
+    if (isa<CXXThisExpr>(MemExpr->getBase()->IgnoreParenCasts()) &&
+       (getLangOpts().AppleKext || !MemExpr->getQualifier())) {
+      Diag(MemExpr->getLocStart(),
            diag::warn_call_to_pure_virtual_member_function_from_ctor_dtor)
         << MD->getDeclName() << isa<CXXDestructorDecl>(CurContext)
         << MD->getParent()->getDeclName();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10935.29118.patch
Type: text/x-patch
Size: 2001 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150706/a7099bd2/attachment.bin>


More information about the cfe-commits mailing list