llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-analysis

Author: Valentyn Yukhymenko (BaLiKfromUA)

<details>
<summary>Changes</summary>

This is the second part of a split of #<!-- -->233219 
(`bugprone-unchecked-expected-access`). It builds on the base
model from #<!-- -->242868 and adds modeling of the equality comparisons.

`operator==` and `operator!=` calls are now modeled when an expected is 
compared with:

- **another expected**: if they are equal, both hold a value or both hold an 
error. Nothing else follows,
  because the values (or errors) themselves may still differ. Two 
`expected&lt;void, E&gt;` objects that both hold
  a value are always equal.
- **a value**: if `e == v`, then `e` holds a value.
- **an `unexpected`**: if `e == u`, then `e` holds an error.

Expected scope of the user-facing changes:
```cpp
void f(std::expected&lt;int, int&gt; a, std::expected&lt;int, int&gt; b) {
  if (a == b &amp;&amp; b)
    *a;            // ok: `a` holds a value because `b` does
  if (a == 5)
    *a;            // ok
  if (a != 5)
    *a;            // diagnosed: unchecked value access
  if (a == std::unexpected(1))
    a.error();     // ok
}
```

### AI usage
I used AI to split my big end-to-end PR 
(https://github.com/llvm/llvm-project/pull/233219) as well as port clang-tidy 
style tests to clang model unit tests.

I also describe how I used AI for 
https://github.com/llvm/llvm-project/pull/233219

Assisted-by: Claude Opus 5.5

---
Full diff: https://github.com/llvm/llvm-project/pull/244872.diff


3 Files Affected:

- (modified) 
clang/lib/Analysis/FlowSensitive/Models/UncheckedExpectedAccessModel.cpp (+141) 
- (modified) clang/unittests/Analysis/FlowSensitive/MockHeaders.cpp (+58-1) 
- (modified) 
clang/unittests/Analysis/FlowSensitive/UncheckedExpectedAccessModelTest.cpp 
(+343-2) 


``````````diff
diff --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedExpectedAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedExpectedAccessModel.cpp
index 1841ebfcaa9a45..b066ea956cbd92 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedExpectedAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedExpectedAccessModel.cpp
@@ -13,6 +13,7 @@
 
 #include "clang/Analysis/FlowSensitive/Models/UncheckedExpectedAccessModel.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/ASTMatchers/ASTMatchersMacros.h"
 #include "clang/Analysis/FlowSensitive/Arena.h"
@@ -51,6 +52,18 @@ static bool isExpectedType(QualType Ty) {
   return RD != nullptr && isExpectedClass(*RD);
 }
 
+/// Returns true if `Ty` is a supported expected type whose value type is
+/// `void`, e.g. `std::expected<void, E>`.
+static bool isVoidExpectedType(QualType Ty) {
+  const auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(
+      Ty->getAsCXXRecordDecl());
+  if (CTSD == nullptr || !isExpectedClass(*CTSD))
+    return false;
+  const TemplateArgument &ValueType = CTSD->getTemplateArgs()[0];
+  return ValueType.getKind() == TemplateArgument::Type &&
+         ValueType.getAsType()->isVoidType();
+}
+
 namespace {
 
 using namespace ::clang::ast_matchers;
@@ -59,6 +72,11 @@ using LatticeTransferState = TransferState<NoopLattice>;
 
 AST_MATCHER(CXXRecordDecl, expectedClass) { return isExpectedClass(Node); }
 
+AST_MATCHER(CXXRecordDecl, unexpectedClass) {
+  return Node.getDeclName().isIdentifier() && Node.getName() == "unexpected" &&
+         isSupportedNamespace(*Node.getDeclContext());
+}
+
 auto expectedMemberCall(ast_matchers::internal::Matcher<NamedDecl> Name) {
   return cxxMemberCallExpr(
       callee(cxxMethodDecl(Name, ofClass(expectedClass()))));
@@ -69,6 +87,64 @@ auto expectedOperatorCall(ArrayRef<StringRef> Names) {
                              callee(cxxMethodDecl(ofClass(expectedClass()))));
 }
 
+auto hasExpectedType() {
+  return hasType(hasUnqualifiedDesugaredType(
+      recordType(hasDeclaration(cxxRecordDecl(expectedClass())))));
+}
+
+auto hasUnexpectedType() {
+  return hasType(hasUnqualifiedDesugaredType(
+      recordType(hasDeclaration(cxxRecordDecl(unexpectedClass())))));
+}
+
+/// Matches `operator==` and `operator!=` calls between an expected and an
+/// operand that matches `Other`, in either order.
+auto expectedComparisonCall(
+    const ast_matchers::internal::Matcher<Expr> &Other) {
+  return cxxOperatorCallExpr(
+      hasAnyOverloadedOperatorName("==", "!="), argumentCountIs(2),
+      anyOf(allOf(hasArgument(0, hasExpectedType()), hasArgument(1, Other)),
+            allOf(hasArgument(0, Other), hasArgument(1, hasExpectedType()))));
+}
+
+auto expectedEqualityCall() {
+  return expectedComparisonCall(hasExpectedType());
+}
+
+auto expectedValueEqualityCall() {
+  return expectedComparisonCall(
+      unless(anyOf(hasExpectedType(), hasUnexpectedType())));
+}
+
+auto expectedUnexpectedEqualityCall() {
+  return expectedComparisonCall(hasUnexpectedType());
+}
+
+/// Ensures that `E` is mapped to a `BoolValue` and returns its formula.
+const Formula &forceBoolValue(Environment &Env, const Expr &E) {
+  auto *Value = Env.get<BoolValue>(E);
+  if (Value != nullptr)
+    return Value->formula();
+
+  Value = &Env.makeAtomicBoolValue();
+  Env.setValue(E, *Value);
+  return Value->formula();
+}
+
+/// Returns the formula that is true if and only if the operands of the
+/// `operator==` or `operator!=` call `E` are equal.
+const Formula &equalityFormula(Environment &Env, const CXXOperatorCallExpr &E) 
{
+  const Formula &Result = forceBoolValue(Env, E);
+  if (E.getOperator() == OO_ExclaimEqual)
+    return Env.arena().makeNot(Result);
+  return Result;
+}
+
+/// Returns the expected operand of the comparison `E`, which has exactly one.
+const Expr &getExpectedOperand(const CXXOperatorCallExpr &E) {
+  return isExpectedType(E.getArg(0)->getType()) ? *E.getArg(0) : *E.getArg(1);
+}
+
 StorageLocation &locForHasValue(const RecordStorageLocation &ExpectedLoc) {
   return ExpectedLoc.getSyntheticField("has_value");
 }
@@ -97,6 +173,61 @@ void transferHasValueCall(const CXXMemberCallExpr *E,
     State.Env.setValue(*E, *HasValueVal);
 }
 
+void transferExpectedEqualityCall(const CXXOperatorCallExpr *E,
+                                  const MatchFinder::MatchResult &,
+                                  LatticeTransferState &State) {
+  Environment &Env = State.Env;
+  BoolValue *LHasValueVal =
+      getHasValue(Env, Env.get<RecordStorageLocation>(*E->getArg(0)));
+  BoolValue *RHasValueVal =
+      getHasValue(Env, Env.get<RecordStorageLocation>(*E->getArg(1)));
+  if (LHasValueVal == nullptr || RHasValueVal == nullptr)
+    return;
+
+  Arena &A = Env.arena();
+  const Formula &EqVal = equalityFormula(Env, *E);
+  const Formula &LHasValue = LHasValueVal->formula();
+  const Formula &RHasValue = RHasValueVal->formula();
+
+  // Equal expecteds either both hold a value or both hold an error. Nothing
+  // more follows in general: the values (or errors) themselves may differ.
+  Env.assume(A.makeImplies(EqVal, A.makeEquals(LHasValue, RHasValue)));
+
+  // `expected<void, E>` objects that both hold a value are always equal.
+  if (isVoidExpectedType(E->getArg(0)->getType()) &&
+      isVoidExpectedType(E->getArg(1)->getType()))
+    Env.assume(A.makeImplies(A.makeAnd(LHasValue, RHasValue), EqVal));
+}
+
+void transferExpectedValueEqualityCall(const CXXOperatorCallExpr *E,
+                                       const MatchFinder::MatchResult &,
+                                       LatticeTransferState &State) {
+  Environment &Env = State.Env;
+  BoolValue *HasValueVal =
+      getHasValue(Env, Env.get<RecordStorageLocation>(getExpectedOperand(*E)));
+  if (HasValueVal == nullptr)
+    return;
+
+  // `e == v` --> `e.has_value() && *e == v`
+  Env.assume(Env.arena().makeImplies(equalityFormula(Env, *E),
+                                     HasValueVal->formula()));
+}
+
+void transferExpectedUnexpectedEqualityCall(const CXXOperatorCallExpr *E,
+                                            const MatchFinder::MatchResult &,
+                                            LatticeTransferState &State) {
+  Environment &Env = State.Env;
+  BoolValue *HasValueVal =
+      getHasValue(Env, Env.get<RecordStorageLocation>(getExpectedOperand(*E)));
+  if (HasValueVal == nullptr)
+    return;
+
+  // `e == u` --> `!e.has_value() && e.error() == u.error()`
+  Arena &A = Env.arena();
+  Env.assume(A.makeImplies(equalityFormula(Env, *E),
+                           A.makeNot(HasValueVal->formula())));
+}
+
 // FIXME: Model the constructors, assignments, `emplace` and `swap`.
 auto buildTransferMatchSwitch() {
   return CFGMatchSwitchBuilder<LatticeTransferState>()
@@ -104,6 +235,16 @@ auto buildTransferMatchSwitch() {
       .CaseOfCFGStmt<CXXMemberCallExpr>(
           expectedMemberCall(hasAnyName("has_value", "operator bool")),
           transferHasValueCall)
+      // operator==, operator!= between two expecteds
+      .CaseOfCFGStmt<CXXOperatorCallExpr>(expectedEqualityCall(),
+                                          transferExpectedEqualityCall)
+      // operator==, operator!= between an expected and a value
+      .CaseOfCFGStmt<CXXOperatorCallExpr>(expectedValueEqualityCall(),
+                                          transferExpectedValueEqualityCall)
+      // operator==, operator!= between an expected and an unexpected
+      .CaseOfCFGStmt<CXXOperatorCallExpr>(
+          expectedUnexpectedEqualityCall(),
+          transferExpectedUnexpectedEqualityCall)
       .Build();
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/MockHeaders.cpp 
b/clang/unittests/Analysis/FlowSensitive/MockHeaders.cpp
index f325b913ae2c7f..9e157efa964f91 100644
--- a/clang/unittests/Analysis/FlowSensitive/MockHeaders.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MockHeaders.cpp
@@ -847,6 +847,12 @@ struct unexpect_t {
 
 inline constexpr unexpect_t unexpect{};
 
+template <class T, class E> class expected;
+
+template <class> constexpr bool __is_expected = false;
+template <class T, class E>
+constexpr bool __is_expected<expected<T, E>> = true;
+
 template <class T, class E> class expected {
 public:
   using value_type = T;
@@ -898,6 +904,20 @@ template <class T, class E> class expected {
   template <class... Args> T &emplace(Args &&...args) noexcept;
 
   void swap(expected &rhs) noexcept;
+
+  // The comparisons rely on C++20 rewritten candidates for `!=` and for
+  // reversed operands.
+#if __cplusplus >= 202002L
+  template <class T2, class E2>
+  friend bool operator==(const expected &x, const expected<T2, E2> &y);
+
+  template <class T2>
+    requires(!__is_expected<T2>)
+  friend bool operator==(const expected &x, const T2 &v);
+
+  template <class E2>
+  friend bool operator==(const expected &x, const unexpected<E2> &e);
+#endif
 };
 
 template <class E> class expected<void, E> {
@@ -938,6 +958,14 @@ template <class E> class expected<void, E> {
   void emplace() noexcept;
 
   void swap(expected &rhs) noexcept;
+
+#if __cplusplus >= 202002L
+  template <class T2, class E2>
+  friend bool operator==(const expected &x, const expected<T2, E2> &y);
+
+  template <class E2>
+  friend bool operator==(const expected &x, const unexpected<E2> &e);
+#endif
 };
 
 } // namespace std
@@ -951,7 +979,9 @@ static constexpr char TlExpectedHeader[] = R"(
 
 // Mock of `tl::expected` from https://github.com/TartanLlama/expected.
 //
-// Unlike `std::expected`, it has no `void` specialization.
+// Unlike `std::expected`, it has no `void` specialization and its comparison
+// operators are free functions that are declared for both operand orders,
+// including `operator!=`.
 
 #include "std_type_traits.h"
 
@@ -1081,6 +1111,33 @@ template <class T, class E> class expected {
   template <class U> T value_or(U &&v) &&;
 };
 
+template <class T, class E, class U, class F>
+bool operator==(const expected<T, E> &lhs, const expected<U, F> &rhs);
+template <class T, class E, class U, class F>
+bool operator!=(const expected<T, E> &lhs, const expected<U, F> &rhs);
+template <class E, class F>
+bool operator==(const expected<void, E> &lhs, const expected<void, F> &rhs);
+template <class E, class F>
+bool operator!=(const expected<void, E> &lhs, const expected<void, F> &rhs);
+
+template <class T, class E, class U>
+bool operator==(const expected<T, E> &x, const U &v);
+template <class T, class E, class U>
+bool operator==(const U &v, const expected<T, E> &x);
+template <class T, class E, class U>
+bool operator!=(const expected<T, E> &x, const U &v);
+template <class T, class E, class U>
+bool operator!=(const U &v, const expected<T, E> &x);
+
+template <class T, class E>
+bool operator==(const expected<T, E> &x, const unexpected<E> &e);
+template <class T, class E>
+bool operator==(const unexpected<E> &e, const expected<T, E> &x);
+template <class T, class E>
+bool operator!=(const expected<T, E> &x, const unexpected<E> &e);
+template <class T, class E>
+bool operator!=(const unexpected<E> &e, const expected<T, E> &x);
+
 template <class T, class E>
 void swap(expected<T, E> &lhs, expected<T, E> &rhs);
 
diff --git 
a/clang/unittests/Analysis/FlowSensitive/UncheckedExpectedAccessModelTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/UncheckedExpectedAccessModelTest.cpp
index 5ef2f3f99db80e..550209c73e9206 100644
--- 
a/clang/unittests/Analysis/FlowSensitive/UncheckedExpectedAccessModelTest.cpp
+++ 
b/clang/unittests/Analysis/FlowSensitive/UncheckedExpectedAccessModelTest.cpp
@@ -62,8 +62,9 @@ class UncheckedExpectedAccessTest
   //   for an unchecked error access on that line.
   void ExpectDiagnosticsFor(std::string SourceCode) {
     // `tl::expected` is usable since C++17, and `std::expected` since C++23.
-    for (const char *CxxMode : {"-std=c++17", "-std=c++23"})
-      ExpectDiagnosticsFor(SourceCode, CxxMode);
+    if (GetParam().NamespaceName == "tl")
+      ExpectDiagnosticsFor(SourceCode, "-std=c++17");
+    ExpectDiagnosticsFor(SourceCode, "-std=c++23");
   }
 
   void ExpectDiagnosticsFor(std::string SourceCode, const char *CxxMode) {
@@ -610,4 +611,344 @@ TEST_P(UncheckedExpectedAccessTest, 
UnexpectedErrorIsNotAnAccess) {
   )");
 }
 
+TEST_P(UncheckedExpectedAccessTest, EqualToExpected) {
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> a, $ns::expected<int, int> b) {
+      if (a == b && b)
+        return *a;
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> a, $ns::expected<int, int> b) {
+      if (a == b && !b)
+        return a.error();
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> a, $ns::expected<int, int> b) {
+      if (a == b) {
+        if (b)
+          return *a;
+      }
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> a, $ns::expected<int, int> b) {
+      if (a != b)
+        return 0;
+      if (b)
+        return *a;
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> a, $ns::expected<long, int> b) {
+      if (a == b && b)
+        return *a;
+      return 0;
+    }
+  )");
+
+  // `expected<void, E>` objects that both hold a value are equal.
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    void target($ns::expected<void, int> a, $ns::expected<void, int> b) {
+      if (a != b && a)
+        b.error();
+    }
+  )");
+}
+
+TEST_P(UncheckedExpectedAccessTest, EqualToExpectedUnchecked) {
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> a, $ns::expected<int, int> b) {
+      if (a == b)
+        return *a; // [[unsafe]]
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> a, $ns::expected<int, int> b) {
+      if (a != b && b)
+        return *a; // [[unsafe]]
+      return 0;
+    }
+  )");
+
+  // Unequal expecteds may both hold values that differ.
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    void target($ns::expected<int, int> a, $ns::expected<int, int> b) {
+      if (a != b && a)
+        b.error(); // [[unsafe:error]]
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> a, $ns::expected<int, int> b) {
+      if (a == b || b)
+        return *a; // [[unsafe]]
+      return 0;
+    }
+  )");
+}
+
+TEST_P(UncheckedExpectedAccessTest, EqualToValue) {
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e == 5)
+        return *e;
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (5 == e)
+        return e.value();
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e != 5)
+        return 0;
+      return *e;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (5 != e)
+        return 0;
+      return *e;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    long target($ns::expected<long, int> e, int v) {
+      if (e == v)
+        return *e;
+      return 0;
+    }
+  )");
+}
+
+TEST_P(UncheckedExpectedAccessTest, EqualToValueUnchecked) {
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e != 5)
+        return *e; // [[unsafe]]
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (5 != e)
+        return *e; // [[unsafe]]
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e == 5)
+        return 0;
+      return *e; // [[unsafe]]
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (5 == e)
+        return 0;
+      return *e; // [[unsafe]]
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e == 5)
+        return e.error(); // [[unsafe:error]]
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e != 5)
+        return e.error(); // [[unsafe:error]]
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e, bool cond) {
+      if (e == 5 || cond)
+        return *e; // [[unsafe]]
+      return 0;
+    }
+  )");
+}
+
+TEST_P(UncheckedExpectedAccessTest, EqualToUnexpected) {
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e == $ns::unexpected(1))
+        return e.error();
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if ($ns::unexpected(1) == e)
+        return e.error();
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e != $ns::unexpected(1))
+        return 0;
+      return e.error();
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if ($ns::unexpected(1) != e)
+        return 0;
+      return e.error();
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    void target($ns::expected<void, int> e) {
+      if (e == $ns::unexpected(1))
+        e.error();
+    }
+  )");
+}
+
+TEST_P(UncheckedExpectedAccessTest, EqualToUnexpectedUnchecked) {
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e == $ns::unexpected(1))
+        return *e; // [[unsafe]]
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if ($ns::unexpected(1) == e)
+        return *e; // [[unsafe]]
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e != $ns::unexpected(1))
+        return e.error(); // [[unsafe:error]]
+      return 0;
+    }
+  )");
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    int target($ns::expected<int, int> e) {
+      if (e == $ns::unexpected(1))
+        return 0;
+      return e.error(); // [[unsafe:error]]
+    }
+  )");
+}
+
+TEST_P(UncheckedExpectedAccessTest, EqualToUnexpectedUncheckedVoidValue) {
+  // `tl::expected<void, E>` has no `value()`.
+  if (GetParam().NamespaceName != "std")
+    GTEST_SKIP();
+
+  ExpectDiagnosticsFor(R"(
+    #include "unchecked_expected_access_test.h"
+
+    void target($ns::expected<void, int> e) {
+      if (e == $ns::unexpected(1))
+        e.value(); // [[unsafe]]
+    }
+  )");
+}
+
 } // namespace clang::dataflow::test

``````````

</details>


https://github.com/llvm/llvm-project/pull/244872
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to