[PATCH] Changed non-const method behaviour.

Christian Wailes chriswailes at google.com
Thu Aug 29 13:11:59 PDT 2013


Hi delesley, dblaikie, aaron.ballman,

Non-const methods no longer transfer an object into an unknown state.

http://llvm-reviews.chandlerc.com/D1549

Files:
  lib/Analysis/Consumed.cpp
  test/SemaCXX/warn-consumed-analysis-strict.cpp
  test/SemaCXX/warn-consumed-analysis.cpp

Index: lib/Analysis/Consumed.cpp
===================================================================
--- lib/Analysis/Consumed.cpp
+++ lib/Analysis/Consumed.cpp
@@ -529,8 +529,6 @@
         handleTestingFunctionCall(Call, PInfo.getVar());
       else if (MethodDecl->hasAttr<ConsumesAttr>())
         StateMap->setState(PInfo.getVar(), consumed::CS_Consumed);
-      else if (!MethodDecl->isConst())
-        StateMap->setState(PInfo.getVar(), consumed::CS_Unknown);
     }
   }
 }
@@ -625,18 +623,10 @@
       checkCallability(PInfo, FunDecl, Call);
       
       if (PInfo.isVar()) {
-        if (isTestingFunction(FunDecl)) {
+        if (isTestingFunction(FunDecl))
           handleTestingFunctionCall(Call, PInfo.getVar());
-          
-        } else if (FunDecl->hasAttr<ConsumesAttr>()) {
+        else if (FunDecl->hasAttr<ConsumesAttr>())
           StateMap->setState(PInfo.getVar(), consumed::CS_Consumed);
-          
-        } else if (const CXXMethodDecl *MethodDecl =
-                     dyn_cast_or_null<CXXMethodDecl>(FunDecl)) {
-          
-          if (!MethodDecl->isConst())
-            StateMap->setState(PInfo.getVar(), consumed::CS_Unknown);
-        }
       }
     }
   }
Index: test/SemaCXX/warn-consumed-analysis-strict.cpp
===================================================================
--- test/SemaCXX/warn-consumed-analysis-strict.cpp
+++ test/SemaCXX/warn-consumed-analysis-strict.cpp
@@ -20,7 +20,7 @@
   
   ConsumableClass<T>& operator=(ConsumableClass<T>  &other);
   ConsumableClass<T>& operator=(ConsumableClass<T> &&other);
-  ConsumableClass<T>& operator=(nullptr_t);
+  ConsumableClass<T>& operator=(nullptr_t) CONSUMES;
   
   template <typename U>
   ConsumableClass<T>& operator=(ConsumableClass<U>  &other);
@@ -174,13 +174,6 @@
   *var; // expected-warning {{invocation of method 'operator*' on object 'var' while it is in an unknown state}}
 }
 
-void testMoveAsignmentish() {
-  ConsumableClass<int> var;
-  
-  var = nullptr;
-  *var; // expected-warning {{invocation of method 'operator*' on object 'var' while it is in an unknown state}}
-}
-
 void testConstAndNonConstMemberFunctions() {
   ConsumableClass<int> var(42);
   
@@ -188,7 +181,7 @@
   *var;
   
   var.nonconstCall();
-  *var; // expected-warning {{invocation of method 'operator*' on object 'var' while it is in an unknown state}}
+  *var;
 }
 
 void testNoWarnTestFromMacroExpansion() {
Index: test/SemaCXX/warn-consumed-analysis.cpp
===================================================================
--- test/SemaCXX/warn-consumed-analysis.cpp
+++ test/SemaCXX/warn-consumed-analysis.cpp
@@ -19,7 +19,7 @@
   
   ConsumableClass<T>& operator=(ConsumableClass<T>  &other);
   ConsumableClass<T>& operator=(ConsumableClass<T> &&other);
-  ConsumableClass<T>& operator=(nullptr_t);
+  ConsumableClass<T>& operator=(nullptr_t) CONSUMES;
   
   template <typename U>
   ConsumableClass<T>& operator=(ConsumableClass<U>  &other);
@@ -251,6 +251,10 @@
   
   *var0;
   *var1; // expected-warning {{invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
+  
+  var1 = ConsumableClass<long>(42);
+  var1 = nullptr;
+  *var1; // expected-warning {{invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
 }
 
 void testConditionalMerge() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1549.1.patch
Type: text/x-patch
Size: 3328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130829/4cab7951/attachment.bin>


More information about the cfe-commits mailing list