any: Tell clang-analyzer a pointer is not nullptr (#107)

Previously, clang-analyzer warned:

    /.../any.h:146:5: warning: Called C++ object pointer is null [core.CallAndMessage]
This commit is contained in:
Brad King 2023-05-17 15:02:57 -04:00 committed by GitHub
parent 5f49573daf
commit 385f9ed3ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -143,6 +143,9 @@ any& any::operator=(const T& val) {
alloc(type->size(), type->alignment()); alloc(type->size(), type->alignment());
type->copyConstruct(value, &val); type->copyConstruct(value, &val);
} else { } else {
#ifdef __clang_analyzer__
assert(value != nullptr);
#endif
*reinterpret_cast<T*>(value) = val; *reinterpret_cast<T*>(value) = val;
} }
return *this; return *this;