[clang] [clang-tools-extra] [clang-tidy] `bugprone-unchecked-optional-access`: Improve handling of value constructors for `bsl::optional` and `bdlb::NullableValue` (PR #224969)
Valentyn Yukhymenko via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 04:36:19 PDT 2026
================
@@ -272,15 +278,29 @@ auto isOptionalNulloptConstructor() {
}
auto isOptionalInPlaceConstructor() {
- return cxxConstructExpr(hasArgument(0, hasType(inPlaceClass())),
+ return cxxConstructExpr(hasAnyArgument(hasType(inPlaceClass())),
hasOptionalOrDerivedType());
}
+// `optional(value, ...)`. Arguments after the value are ignored. Tag types are
+// excluded because they denote other constructions.
auto isOptionalValueOrConversionConstructor() {
return cxxConstructExpr(
unless(hasDeclaration(
cxxConstructorDecl(anyOf(isCopyConstructor(), isMoveConstructor())))),
- argumentCountIs(1), hasArgument(0, unless(hasNulloptType())),
+ argumentCountAtLeast(1),
+ hasArgument(0, unless(anyOf(hasNulloptType(), hasType(inPlaceClass()),
+ hasAllocatorArgType()))),
+ hasOptionalOrDerivedType());
+}
+
+// `optional(allocator_arg_t, allocator, value, ...)`.
----------------
BaLiKfromUA wrote:
Done https://github.com/llvm/llvm-project/pull/224969/changes/282ed09e677cd9880a6de1855aaf2e60d5f858e9
JFYI, we might want to limit matchers to only Bloomberg components but maybe it's an overkill.
https://github.com/llvm/llvm-project/pull/224969
More information about the cfe-commits
mailing list