diff options
author | AMS21 <AMS21.github@gmail.com> | 2023-04-04 06:38:40 +0000 |
---|---|---|
committer | Piotr Zegar <me@piotrzegar.pl> | 2023-04-04 07:20:25 +0000 |
commit | 25956d55d02489964428ab5f55e609ff16c6632d (patch) | |
tree | 21379e2ffb952a47f4f99e1cf200fac09076112f /clang-tools-extra/test | |
parent | 3afe3dbfa0157608aa1d058f6be28e0060aaf9c6 (diff) | |
download | llvm-25956d55d02489964428ab5f55e609ff16c6632d.tar.gz |
[clang-tidy] Allow bugprone-unchecked-optional-access to handle calls to `std::forward`
The check now understands that calling `std::forward`
will not modify the underlying optional value.
This fixes llvm#59705
Reviewed By: PiotrZSL
Differential Revision: https://reviews.llvm.org/D147383
Diffstat (limited to 'clang-tools-extra/test')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp index 6c79dad93e90..c1e731f41171 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp @@ -110,3 +110,50 @@ class C4 { } int foo_; }; + +// llvm#59705 +namespace std +{ + template <typename T> + constexpr T&& forward(T& type) noexcept { + return static_cast<T&&>(type); + } + + template <typename T> + constexpr T&& forward(T&& type) noexcept { + return static_cast<T&&>(type); + } +} + +void std_forward_copy(absl::optional<int> opt) { + std::forward<absl::optional<int>>(opt).value(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: unchecked access to optional +} + +void std_forward_copy_safe(absl::optional<int> opt) { + if (!opt) return; + + std::forward<absl::optional<int>>(opt).value(); +} + +void std_forward_copy(absl::optional<int>& opt) { + std::forward<absl::optional<int>>(opt).value(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: unchecked access to optional +} + +void std_forward_lvalue_ref_safe(absl::optional<int>& opt) { + if (!opt) return; + + std::forward<absl::optional<int>>(opt).value(); +} + +void std_forward_copy(absl::optional<int>&& opt) { + std::forward<absl::optional<int>>(opt).value(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: unchecked access to optional +} + +void std_forward_rvalue_ref_safe(absl::optional<int>&& opt) { + if (!opt) return; + + std::forward<absl::optional<int>>(opt).value(); +} |