diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-10 19:25:56 +0900 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-10 19:25:56 +0900 |
commit | 63f5dc16d6bfca0512fb034052b41d13c3751e20 (patch) | |
tree | e70266be1fda941e0974e71e3d2c1cf080081311 /clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp | |
parent | 9e5734688ed3d5f6b3fb76a26b3d90a736d60781 (diff) | |
parent | 397ac44f623f891d8f05d6673a95984ac0a26671 (diff) | |
download | llvm-users/chapuni/cov/single/unify.zip llvm-users/chapuni/cov/single/unify.tar.gz llvm-users/chapuni/cov/single/unify.tar.bz2 |
Merge branch 'main' into users/chapuni/cov/single/unifyusers/chapuni/cov/single/unify
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp')
-rw-r--r-- | clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp index de16f6b..19c3ff4 100644 --- a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp @@ -3771,6 +3771,54 @@ TEST_P(UncheckedOptionalAccessTest, ConstPointerAccessorWithModInBetween) { /*IgnoreSmartPointerDereference=*/false); } +TEST_P(UncheckedOptionalAccessTest, SmartPointerAccessorMixed) { + ExpectDiagnosticsFor(R"cc( + #include "unchecked_optional_access_test.h" + + struct A { + $ns::$optional<int> x; + }; + + namespace absl { + template<typename T> + class StatusOr { + public: + bool ok() const; + + const T& operator*() const&; + T& operator*() &; + + const T* operator->() const; + T* operator->(); + + const T& value() const; + T& value(); + }; + } + + void target(absl::StatusOr<A> &mut, const absl::StatusOr<A> &imm) { + if (!mut.ok() || !imm.ok()) + return; + + if (mut->x.has_value()) { + mut->x.value(); + ((*mut).x).value(); + (mut.value().x).value(); + + // check flagged after modifying + mut = imm; + mut->x.value(); // [[unsafe]] + } + if (imm->x.has_value()) { + imm->x.value(); + ((*imm).x).value(); + (imm.value().x).value(); + } + } + )cc", + /*IgnoreSmartPointerDereference=*/false); +} + TEST_P(UncheckedOptionalAccessTest, ConstBoolAccessor) { ExpectDiagnosticsFor(R"cc( #include "unchecked_optional_access_test.h" |