mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
src: use stricter compile-time guidance
SnapshotSerializerDeserializer::GetName() appears to confuse static analysis such as Coverity. This changes the function structure to a sequence of if-else blocks and marks all branch conditions as constexpr. (Unfortunately, this results in a dangling 'else' keyword in the V macro.) As per a request in the PR discussion, this change does _not_ ensure that GetName<T>() can only be called for known types T and instead still returns an empty string in that case. Also use std::is_unsigned_v instead of !std::is_signed_v. PR-URL: https://github.com/nodejs/node/pull/46509 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
This commit is contained in:
1 parent
812e236df9
commit
aa3dbe30c9
1 file changed
+8
-11
@@ -166,22 +166,19 @@ class SnapshotSerializerDeserializer {
|
||||
V(std::string)
|
||||
|
||||
#define V(TypeName) \
|
||||
if (std::is_same_v<T, TypeName>) { \
|
||||
if constexpr (std::is_same_v<T, TypeName>) { \
|
||||
return #TypeName; \
|
||||
}
|
||||
} else // NOLINT(readability/braces)
|
||||
TYPE_LIST(V)
|
||||
#undef V
|
||||
|
||||
std::string name;
|
||||
if (std::is_arithmetic_v<T>) {
|
||||
if (!std::is_signed_v<T>) {
|
||||
name += "u";
|
||||
}
|
||||
name += std::is_integral_v<T> ? "int" : "float";
|
||||
name += std::to_string(sizeof(T) * 8);
|
||||
name += "_t";
|
||||
if constexpr (std::is_arithmetic_v<T>) {
|
||||
return (std::is_unsigned_v<T> ? "uint"
|
||||
: std::is_integral_v<T> ? "int"
|
||||
: "float") +
|
||||
std::to_string(sizeof(T) * 8) + "_t";
|
||||
}
|
||||
return name;
|
||||
return "";
|
||||
}
|
||||
|
||||
bool is_debug = false;
|
||||
|
||||
Reference in new issue
Block a user