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

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 21 09:35:03 PDT 2024


================
@@ -0,0 +1,35 @@
+//===--- ReturnConstRefFromParameterCheck.h - clang-tidy --------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RETURNCONSTREFFROMPARAMETERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RETURNCONSTREFFROMPARAMETERCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Detects the function which returns the const reference from parameter which
+/// causes potential use after free if the caller uses xvalue as argument.
----------------
5chmidti wrote:

I think `Detects statements that return constant` should actually be `Detects return statements that return constant`.

As for consistency: in docs/clang-tidy, there are ~116 const's (minus `const` in code snippets and check names) where ~50% of them are in ``, and there are 91 constants (although 60 are in `identifier-naming.rst`.

`might cause potential` sounds not right to me, the `might` and `potential` mean the same thing IMO. 
I would suggest: `This might cause use-after-free errors ...` (or with `may` instead of `might`)

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


More information about the cfe-commits mailing list