[clang-tools-extra] Add `std::span` to default `bugprone-dangling-handle.HandleClasses` (PR #107711)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 7 10:19:57 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Afonso Faria (oracle-9)
<details>
<summary>Changes</summary>
`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};
}
```
---
Full diff: https://github.com/llvm/llvm-project/pull/107711.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp (+2-2)
``````````diff
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) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/107711
More information about the cfe-commits
mailing list