[cfe-commits] r81460 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/attr-deprecated.cpp

Anders Carlsson andersca at mac.com
Thu Sep 10 13:48:15 PDT 2009


Author: andersca
Date: Thu Sep 10 15:48:14 2009
New Revision: 81460

URL: http://llvm.org/viewvc/llvm-project?rev=81460&view=rev
Log:
Don't check use of a member function declaration used if the member function is virtual and the member reference expression doesn't explicitly qualify it. Fixes PR4878.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/attr-deprecated.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=81460&r1=81459&r2=81460&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 10 15:48:14 2009
@@ -2142,8 +2142,16 @@
     if (MemberDecl->isInvalidDecl())
       return ExprError();
 
+    bool ShouldCheckUse = true;
+    if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(MemberDecl)) {
+      // Don't diagnose the use of a virtual member function unless it's
+      // explicitly qualified.
+      if (MD->isVirtual() && (!SS || !SS->isSet()))
+        ShouldCheckUse = false;
+    }
+    
     // Check the use of this field
-    if (DiagnoseUseOfDecl(MemberDecl, MemberLoc))
+    if (ShouldCheckUse && DiagnoseUseOfDecl(MemberDecl, MemberLoc))
       return ExprError();
 
     if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {

Modified: cfe/trunk/test/SemaCXX/attr-deprecated.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-deprecated.cpp?rev=81460&r1=81459&r2=81460&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/attr-deprecated.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-deprecated.cpp Thu Sep 10 15:48:14 2009
@@ -24,3 +24,20 @@
   (void)b;
   (void)a->b;
 }
+
+struct B {
+  virtual void f() __attribute__((deprecated));
+};
+
+struct C : B {
+  virtual void f();
+};
+
+void f(B* b, C *c) {
+  b->f();
+  b->B::f(); // expected-warning{{'f' is deprecated}}
+  
+  c->f();
+  c->C::f();
+  c->B::f(); // expected-warning{{'f' is deprecated}}
+}





More information about the cfe-commits mailing list