[clang-tools-extra] [tidy] add new check bugprone-return-const-ref-from-parameter (PR #89497)

Danny Mösch via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 20 07:26:07 PDT 2024


================
@@ -0,0 +1,30 @@
+.. title:: clang-tidy - bugprone-return-const-ref-from-parameter
+
+bugprone-return-const-ref-from-parameter
+========================================
+
+Detects the function which returns the const reference from parameter which
+causes potential use after free if the caller uses xvalue as argument.
+
+In c++, const reference parameter can accept xvalue which will be destructed
+after the call. When the function returns this parameter also as const reference,
+then the returned reference can be used after the object it refers to has been
+destroyed.
----------------
SimplyDanny wrote:

```suggestion
In C++, constant reference parameters can accept xvalues which will be destructed
after the call. When the function returns such a parameter also as constant reference,
then the returned reference can be used after the object it refers to has been
destroyed.
```

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


More information about the cfe-commits mailing list