[clang-tools-extra] Add `std::span` to default `bugprone-dangling-handle.HandleClasses` (PR #107711)
Afonso Faria via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 7 10:19:12 PDT 2024
https://github.com/oracle-9 created https://github.com/llvm/llvm-project/pull/107711
`std::span` suffers from the same dangling issues as `std::string_view`. This patch adds `std::span` to the default list of handle classes in `bugprone-dangling-handle`, allowing clang-tidy to catch e.g. the following:
```cpp
span<int> f() {
// All these return values will dangle.
array<int, 1> A;
return {A};
vector<int> Array;
return {Array};
}
```
>From 8528404715b4ca6dec7e251548870aba0c64bb04 Mon Sep 17 00:00:00 2001
From: Afonso Faria <oracle-main at protonmail.com>
Date: Sat, 7 Sep 2024 18:03:48 +0100
Subject: [PATCH] Add std::span to default
bugprone-dangling-handle.HandleClasses
---
clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
index d55df3a6d7b741..e13b1ceacc5395 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -97,8 +97,8 @@ DanglingHandleCheck::DanglingHandleCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
HandleClasses(utils::options::parseStringList(Options.get(
- "HandleClasses",
- "std::basic_string_view;std::experimental::basic_string_view"))),
+ "HandleClasses", "std::basic_string_view;std::experimental::basic_"
+ "string_view;std::span"))),
IsAHandle(cxxRecordDecl(hasAnyName(HandleClasses)).bind("handle")) {}
void DanglingHandleCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
More information about the cfe-commits
mailing list