================
@@ -440,3 +440,45 @@ namespace call_with_adopt_ref {
     adoptRef(new Obj)->method();
   }
 }
+
+namespace call_on_member {
+
+  class SomeObj {
+  public:
+    static Ref<SomeObj> create() { return adoptRef(*new SomeObj); }
+
+    void ref() const;
+    void deref() const;
+
+    void doWork() {
+      m_obj->method();
+      // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+      m_obj.get()->method();
+      // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+      m_constObj->method();
----------------
steakhal wrote:

This actually demonstrate a case I had in mind.
The `method` CXXMethodDecl has 2 overloads. One is const, the other one is 
non-const.
Because of the const-rules of C++, calling `method` on a mutable object will 
resolve to the non-const overload - while it could have also bind to the 
`const` overload instead.

This would mean unnecessary constifying casts that is alien for C++ code, just 
for the sake of suppressing this diagnostics.

Now, the solution for this for sensible code would be to see if there would be 
a similar overload in the set that would bind if `this` was `const`. (and also 
assuming that the overload set elements share their semantics, so any of those 
could be substituted for the other).

Checking this would be somewhat complicated but let's keep this limitation in 
mind and if it occurs often enough, then we should think about solving this 
somehow.

https://github.com/llvm/llvm-project/pull/184243
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to