googletest icon indicating copy to clipboard operation
googletest copied to clipboard

[Bug/feature request]: Types requiring comparison with literal 0 do not compile in assertions

Open horenmar opened this issue 2 years ago • 0 comments

Describe the issue

I wanted to check the result of custom spaceship operator via EXPECT_EQ. This does not compile, because the result of spaceship operator is one of the std::ordering_* types, which are defined to be only comparable with literal 0.

Just to check, I also tried pointer comparison with NULL, which does not compile either.

Steps to reproduce the problem

Try compiling this simple test file with C++20 enabled (godbolt link for convenience):

test.cpp

#include <gtest/gtest.h>

TEST(Cpp20, Spaceship) {
    int a = 1, b = 1;
    EXPECT_EQ(a <=> b, 0);
}

TEST(Ptr, Cmp) {
    int* p = NULL;
    EXPECT_EQ(p, NULL);
}

Neither of these two compiles, although the equivalent if ((a <=> b) == 0) and if (p == NULL) would compile, and without warnings.

What version of GoogleTest are you using?

e38ef3be887afc0089005e394c5001002e313960

What operating system and version are you using?

not relevant to the issue

What compiler and version are you using?

MSVC 19.29.30147.0, can be reproduced on clang and gcc as well

What build system are you using?

not relevant to the issue

Additional context

No response

horenmar avatar Dec 14 '22 11:12 horenmar