[clang-tools-extra] [clang-tidy] Add check bugprone-misleading-setter-of-reference (PR #132242)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Tue May 6 06:56:38 PDT 2025


================
@@ -0,0 +1,47 @@
+.. title:: clang-tidy - bugprone-misleading-setter-of-reference
+
+bugprone-misleading-setter-of-reference
+=======================================
+
+Finds setter-like member functions that take a pointer parameter and set a
+(non-const) reference member of the same class with the pointed value.
+
+The checker detects public member functions that have a single parameter (which
+is a pointer) and contain a single (maybe overloaded) assignment operator call.
+The assignment should set a member variable with the dereference of the
+parameter pointer. The member variable can have any visibility.
----------------
NagyDonat wrote:

```suggestion
The checker detects public member functions that take a single pointer
parameter, and contain a single expression statement that dereferences the
parameter and assigns the result to a data member with a reference type.
```
This paragraph was a bit unclear, because it tries to describe a very complex situation. I tried to reword it (with some help from Endre) to make it easier to understand. 

In my suggestion I don't explicitly mention "(maybe overloaded)" and "any visibility" because those are the defaults from the point of view from the user: in theory overloaded assignment operators are equivalent to built-in ones and if we don't speak about constraints on the visibility of a data member, then we imply that it can have any visibility.

https://github.com/llvm/llvm-project/pull/132242


More information about the cfe-commits mailing list