[clang] [clang-tools-extra] [clang-tidy] Add `bugprone-unchecked-expected-access` check (PR #233219)
Valentyn Yukhymenko via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 18 04:14:35 PDT 2026
================
@@ -0,0 +1,85 @@
+//===-- UncheckedExpectedAccessModel.h --------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines a dataflow analysis that detects unsafe accesses to the
+// values of `std::expected` objects.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_ANALYSIS_FLOWSENSITIVE_MODELS_UNCHECKEDEXPECTEDACCESSMODEL_H
+#define CLANG_ANALYSIS_FLOWSENSITIVE_MODELS_UNCHECKEDEXPECTEDACCESSMODEL_H
+
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/NoopLattice.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace clang {
+namespace dataflow {
+
+/// Dataflow analysis that models whether `std::expected` objects hold values.
+class UncheckedExpectedAccessModel
----------------
BaLiKfromUA wrote:
Nit: IIUC, Dataflow models are located inside `clang` so we could reuse them outside of `clang-tidy`.
Since my model is used only for `clang-tidy`, should I move it out of this directory?.
https://github.com/llvm/llvm-project/pull/233219
More information about the cfe-commits
mailing list