Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use stricter compile-time guidance #46509

Merged

Conversation

tniessen
Copy link
Member

@tniessen tniessen commented Feb 5, 2023

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 a side effect, this change ensures that GetName<T>() can only be called for known types T (instead of returning an empty string). 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.

@tniessen tniessen added the c++ Issues and PRs that require attention from people who are familiar with C++. label Feb 5, 2023
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Feb 5, 2023
@joyeecheung
Copy link
Member

joyeecheung commented Feb 5, 2023

As a side effect, this change ensures that GetName() can only be called for known types T (instead of returning an empty string).

Why would this be necessary? This is a debugging facility that decorates the log output, it would be fine to just give up if "I don't know what it's called, so I won't attempt to tell you what the type name is, because RTTI is disallowed" (I think I relied on this when developing deserialization/serialization of new types, which was fine because it's possible to guess the name from the context anyway).

@tniessen
Copy link
Member Author

tniessen commented Feb 5, 2023

Why would this be necessary?

It's certainly not necessary. I can change it to allow unknown types, but unless I'm missing something, I don't really see the point. Wouldn't it only take a one-line change to add new non-arithmetic types?

@tniessen
Copy link
Member Author

@joyeecheung is your comment blocking?

@tniessen tniessen added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Feb 19, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 19, 2023
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@joyeecheung
Copy link
Member

joyeecheung commented Feb 19, 2023

Sorry for missing the ping. I wouldn't say it's a hill that I'd die on but it's also weird that this restriction exists. The function is just a utility that attempts to assemble a human-readable name for a type (or it's just poor-man's RTTI). Returning an empty string for a type that we don't special case is totally acceptable. Does the static analyzer complain about it? If it does it would make more sense to do if (!std::is_arithmetic_v<T>) { return ""; /* gives up */ } than adding a static assert.

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.
@tniessen tniessen force-pushed the src-snapshotable-getname-constexpr branch from 451850a to 8ddfb52 Compare March 29, 2023 12:26
@tniessen
Copy link
Member Author

@joyeecheung Sorry about the delay, I've updated the PR as requested. PTAL.

@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 29, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 29, 2023
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@tniessen tniessen added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 4, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 4, 2023
@nodejs-github-bot nodejs-github-bot merged commit aa3dbe3 into nodejs:main Apr 4, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in aa3dbe3

RafaelGSS pushed a commit that referenced this pull request Apr 5, 2023
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>
RafaelGSS pushed a commit that referenced this pull request Apr 5, 2023
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>
@RafaelGSS RafaelGSS mentioned this pull request Apr 6, 2023
RafaelGSS pushed a commit that referenced this pull request Apr 6, 2023
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>
RafaelGSS pushed a commit that referenced this pull request Apr 7, 2023
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>
RafaelGSS pushed a commit that referenced this pull request Apr 8, 2023
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>
RafaelGSS pushed a commit that referenced this pull request Apr 13, 2023
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>
danielleadams pushed a commit that referenced this pull request Jul 6, 2023
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>
MoLow pushed a commit to MoLow/node that referenced this pull request Jul 6, 2023
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: nodejs#46509
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants