Skip to content

_Literal_zero_is_expected() referenced in <compare> not defined anywhere? #4697

Answered by StephanTLavavej
DTBob asked this question in General
Discussion options

You must be logged in to vote

It's intentionally never defined. If you're seeing this, you've got code somewhere that's attempting to compare a spaceship operator result against an int that isn't a literal 0.

C:\Temp>type meow.cpp
#include <compare>
#include <print>
#include <string>
using namespace std;

int main() {
    const string cats{"cats"};
    const string dogs{"dogs"};
    println("(cats <=> dogs) < 0: {}", (cats <=> dogs) < 0);
#ifndef SKIP_BAD_CODE
    println("(cats <=> dogs) < 5: {}", (cats <=> dogs) < 5);
#endif
}
C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /DSKIP_BAD_CODE meow.cpp && meow
meow.cpp
(cats <=> dogs) < 0: true

C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od meow.cpp && meow…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@DTBob
Comment options

Answer selected by CaseyCarter
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants