r242857 - [Sema] Diagnose use of declaration correctly.

Davide Italiano davide at freebsd.org
Tue Jul 21 17:30:58 PDT 2015


Author: davide
Date: Tue Jul 21 19:30:58 2015
New Revision: 242857

URL: http://llvm.org/viewvc/llvm-project?rev=242857&view=rev
Log:
[Sema] Diagnose use of declaration correctly.

Before we skipped that for virtual functions not fully qualified (r81507).
This commit basically reverts this to the older behaviour, which seems
more consistent. We now also correctly consider ill-formed calls to deleted
member functions, which were silently passed before in some cases.
The review contains the whole discussion.

PR:		20268
Differential Revision:	 http://reviews.llvm.org/D11334

Added:
    cfe/trunk/test/SemaCXX/deleted-function-access.cpp
Modified:
    cfe/trunk/lib/Sema/SemaExprMember.cpp
    cfe/trunk/test/SemaCXX/attr-deprecated.cpp

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=242857&r1=242856&r2=242857&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Tue Jul 21 19:30:58 2015
@@ -1042,16 +1042,8 @@ Sema::BuildMemberReferenceExpr(Expr *Bas
     BaseExpr = new (Context) CXXThisExpr(Loc, BaseExprType,/*isImplicit=*/true);
   }
 
-  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.isSet())
-      ShouldCheckUse = false;
-  }
-
   // Check the use of this member.
-  if (ShouldCheckUse && DiagnoseUseOfDecl(MemberDecl, MemberLoc))
+  if (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=242857&r1=242856&r2=242857&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-deprecated.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-deprecated.cpp Tue Jul 21 19:30:58 2015
@@ -26,12 +26,12 @@ void A::h(A* a)
 }
 
 struct B {
-  virtual void f() __attribute__((deprecated)); // expected-note 4 {{'f' has been explicitly marked deprecated here}}
+  virtual void f() __attribute__((deprecated)); // expected-note 6 {{'f' has been explicitly marked deprecated here}}
   void g();
 };
 
 void B::g() {
-  f();
+  f(); // expected-warning{{'f' is deprecated}}
   B::f(); // expected-warning{{'f' is deprecated}}
 }
 
@@ -47,7 +47,7 @@ void C::g() {
 }
 
 void f(B* b, C *c) {
-  b->f();
+  b->f(); // expected-warning{{'f' is deprecated}}
   b->B::f(); // expected-warning{{'f' is deprecated}}
   
   c->f();
@@ -59,10 +59,10 @@ struct D {
   virtual void f() __attribute__((deprecated));
 };
 
-void D::f() { }
+void D::f() { } // expected-note{{'f' has been explicitly marked deprecated here}}
 
 void f(D* d) {
-  d->f();
+  d->f(); // expected-warning{{'f' is deprecated}}
 }
 
 

Added: cfe/trunk/test/SemaCXX/deleted-function-access.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/deleted-function-access.cpp?rev=242857&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/deleted-function-access.cpp (added)
+++ cfe/trunk/test/SemaCXX/deleted-function-access.cpp Tue Jul 21 19:30:58 2015
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+struct S {
+    virtual void f() = delete; //expected-note{{'f' has been explicitly marked deleted here}}
+    void g() { f(); } //expected-error{{attempt to use a deleted function}}
+};





More information about the cfe-commits mailing list