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

Don't warn when using operator<=> with 0 #3581

Merged
merged 6 commits into from
Mar 24, 2023

Conversation

fsb4000
Copy link
Contributor

@fsb4000 fsb4000 commented Mar 19, 2023

LLVM has an issue: llvm/llvm-project#43670

That issue marked as libc++ but actually every C++ standard library affected , and MSVC STL and libstdc++.

#include <compare>

auto b = 1 <=> 2 < 0;

int main() {}
clang-cl /std:c++20 -Wzero-as-null-pointer-constant main.cpp
main.cpp(3,20): warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
auto b = 1 <=> 2 < 0;
                   ^
                   nullptr
1 warning generated.

изображение

I also created: https://reviews.llvm.org/D146372

Yes, after that patch we accept

auto b = 1 <=> 2 < (1-1);

but probably this is fine because the behavior is undefined. At least we don't warn on valid code.

@fsb4000 fsb4000 requested a review from a team as a code owner March 19, 2023 05:15
stl/inc/compare Outdated Show resolved Hide resolved
stl/inc/compare Outdated Show resolved Hide resolved
stl/inc/compare Outdated Show resolved Hide resolved
stl/inc/compare Show resolved Hide resolved
stl/inc/compare Outdated Show resolved Hide resolved
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Mar 19, 2023
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
Copy link
Contributor

@strega-nil-ms strega-nil-ms left a comment

Choose a reason for hiding this comment

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

This looks good to me, at least :)

stl/inc/compare Outdated Show resolved Hide resolved
tests/std/tests/P0768R1_spaceship_operator/test.cpp Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

Thanks! FYI @strega-nil-ms I pushed very minor changes after you approved.

@StephanTLavavej StephanTLavavej self-assigned this Mar 23, 2023
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 581b4f0 into microsoft:main Mar 24, 2023
@StephanTLavavej
Copy link
Member

Thanks for restoring the usability of the zero-as-null-pointer-constant warning! ⚠️ 😸 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants