Issue 61624
Summary readability-make-member-function-const could detect more cases where a pointer member is read but not dereferenced
Labels clang-tidy
Assignees
Reporter sfc-gh-sgiesecke
    readability-make-member-function-const doesn't suggest declaring member functions `const` which could be `const`, where a pointer member is read but not dereferenced, such as any of the following:
```
#include <memory>

struct foo {

    bool hasPlain() {
        return m_plain_ptr != nullptr;
    }

 bool hasPlainImplicitCast() {
        return m_plain_ptr;
    }

 bool hasPlainExplicitCast() {
        return static_cast<bool>(m_plain_ptr);
    }

    bool hasUnique() {
 return m_unique_ptr != nullptr;
    }

    bool hasUniqueGet() {
        return m_unique_ptr.get() != nullptr;
    }

    bool hasUniqueExplicitCast() {
        return static_cast<bool>(m_unique_ptr);
    }

private:
  int* m_plain_ptr;
  std::unique_ptr<int> m_unique_ptr;
};
```

See also https://godbolt.org/z/W8Mr6TPKq

I think the argument 
> Specifically, this check will not suggest to add a const to a non-const method if the method reads a private member variable of pointer type because that allows to modify the pointee which might not preserve logical constness.

doesn't apply if the pointer is never dereferenced.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to