From 2ee1bfcaa1e75c6fc3c92f45d7df6f8dd3cc84bb Mon Sep 17 00:00:00 2001 From: Sergei Shirokov Date: Tue, 3 Dec 2024 11:57:26 +0200 Subject: [PATCH] An attempt to fix clang-tidy false positive #verification #docs #sonar --- include/cetl/unbounded_variant.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/cetl/unbounded_variant.hpp b/include/cetl/unbounded_variant.hpp index 3d6404c..f36dc41 100644 --- a/include/cetl/unbounded_variant.hpp +++ b/include/cetl/unbounded_variant.hpp @@ -657,7 +657,9 @@ struct base_access : base_storage // Non-PMR storage can store any value as long as it fits into the footprint. static_assert((Footprint > 0) || IsPmr::value, "Make non-zero footprint, or enable PMR support."); - if (has_value()) + // `has_value()` already checks for `value_destroyer_` not being `nullptr`, + // but clang-tidy doesn't see it, so we get false positive here - hence the explicit double check. + if (has_value() && (nullptr != value_destroyer_)) { value_destroyer_(base::get_raw_storage()); }