[clang] [clang-tools-extra] [clang-tidy] `bugprone-unchecked-optional-access`: handle `BloombergLP::bdlb:NullableValue::makeValue` to prevent false-positives (PR #144313)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 23 03:06:16 PDT 2025


================
@@ -985,6 +985,20 @@ auto buildTransferMatchSwitch() {
           isOptionalMemberCallWithNameMatcher(hasName("isNull")),
           transferOptionalIsNullCall)
 
+      // NullableValue::makeValue, NullableValue::makeValueInplace
+      // Only NullableValue has these methods, but this
+      // will also pass for other types
+      .CaseOfCFGStmt<CXXMemberCallExpr>(
+          isOptionalMemberCallWithNameMatcher(
+              hasAnyName("makeValue", "makeValueInplace")),
+          [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &,
+             LatticeTransferState &State) {
+            if (RecordStorageLocation *Loc =
+                    getImplicitObjectLocation(*E, State.Env)) {
+              setHasValue(*Loc, State.Env.getBoolLiteralValue(true), State.Env);
+            }
+          })
+
----------------
vbvictor wrote:

You can look at [no-malloc check](https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/no-malloc.html) for similar option with function names.

You can add function-lists both for `bdlb` and other libraries. The code must be very similar.

https://github.com/llvm/llvm-project/pull/144313


More information about the cfe-commits mailing list