Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0fbfb28

Browse filesBrowse files
tniessenMoLow
authored andcommitted
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: #46509 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 116df2a commit 0fbfb28
Copy full SHA for 0fbfb28

File tree

Expand file treeCollapse file tree

1 file changed

+8
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-11
lines changed
Open diff view settings
Collapse file

‎src/node_snapshotable.cc‎

Copy file name to clipboardExpand all lines: src/node_snapshotable.cc
+8-11Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,19 @@ class SnapshotSerializerDeserializer {
163163
V(std::string)
164164

165165
#define V(TypeName) \
166-
if (std::is_same_v<T, TypeName>) { \
166+
if constexpr (std::is_same_v<T, TypeName>) { \
167167
return #TypeName; \
168-
}
168+
} else // NOLINT(readability/braces)
169169
TYPE_LIST(V)
170170
#undef V
171171

172-
std::string name;
173-
if (std::is_arithmetic_v<T>) {
174-
if (!std::is_signed_v<T>) {
175-
name += "u";
176-
}
177-
name += std::is_integral_v<T> ? "int" : "float";
178-
name += std::to_string(sizeof(T) * 8);
179-
name += "_t";
172+
if constexpr (std::is_arithmetic_v<T>) {
173+
return (std::is_unsigned_v<T> ? "uint"
174+
: std::is_integral_v<T> ? "int"
175+
: "float") +
176+
std::to_string(sizeof(T) * 8) + "_t";
180177
}
181-
return name;
178+
return "";
182179
}
183180

184181
bool is_debug = false;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.