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

Add MSVC coverage for remaining suspicious asserts #365

Merged
merged 6 commits into from
Dec 18, 2024

Conversation

chiphogg
Copy link
Contributor

@chiphogg chiphogg commented Dec 18, 2024

I went through every static_assert in our C++ files, and added MSVC
test coverage for any that looked like they might be vulnerable to the
same error as in #363.

I added these test cases one at a time, so I could tell which ones
failed.

  • The is_known_to_be_less_than_one "bug" never actually failed,
    whether I called it directly or indirectly. I'm leaving the tests in
    place, and I "fixed" it anyway because it made the function body more
    stylistically consistent.

  • The inverse_as/inverse_in bug was indeed another instance of this
    problem. Now we have coverage and a fix.

Fixes #364.

@chiphogg chiphogg marked this pull request as ready for review December 18, 2024 16:29
@geoffviola geoffviola self-requested a review December 18, 2024 16:35
Copy link
Contributor

@geoffviola geoffviola left a comment

Choose a reason for hiding this comment

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

The change seems fine. I'm not sure I understand the original issue. The error that I see is

failure was caused by a read of a variable outside its lifetime

But I don't see how that is possible 😕

With the changes to single-file-test.cc, I see the issue in godbolt. So the coverage seems better.

As an aside, can we get constants in the single file deployment? 😄 It doesn't seem to have SPEED_OF_LIGHT.

@chiphogg
Copy link
Contributor Author

The change seems fine. I'm not sure I understand the original issue. The error that I see is

failure was caused by a read of a variable outside its lifetime

But I don't see how that is possible 😕

I found this super confusing as well. The key is that "outside" in this case probably means "before". It's running "at compile time", but we're using the value of a variable that won't exist until runtime. At least, that's the nearest I can figure.

As an aside, can we get constants in the single file deployment? 😄 It doesn't seem to have SPEED_OF_LIGHT.

Those single-file releases are barebones. Check out the "Pre-built files with all units" box from the single file section of the install instructions. They should all be there! And, they're also in our canonical godbolt link from the README.md.

@chiphogg chiphogg merged commit 8165cb6 into main Dec 18, 2024
14 checks passed
@chiphogg chiphogg deleted the chiphogg/remaining-static-assert-issues#364 branch December 18, 2024 17:47
@hoffbrinkle
Copy link
Contributor

failure was caused by a read of a variable outside its lifetime

But I don't see how that is possible 😕

I found this super confusing as well. The key is that "outside" in this case probably means "before". It's running "at compile time", but we're using the value of a variable that won't exist until runtime. At least, that's the nearest I can figure.

Interesting. Is this an "issue" with MSVC? We're using it at compile time, but are we using any information that isn't available at compile time?

@chiphogg
Copy link
Contributor Author

failure was caused by a read of a variable outside its lifetime

But I don't see how that is possible 😕

I found this super confusing as well. The key is that "outside" in this case probably means "before". It's running "at compile time", but we're using the value of a variable that won't exist until runtime. At least, that's the nearest I can figure.

Interesting. Is this an "issue" with MSVC? We're using it at compile time, but are we using any information that isn't available at compile time?

Possibly! But I think we'd need to go deep into "language lawyer" territory to definitively say who is right. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Constant is broken on MSVC
3 participants