Fix cppcheckError with spaceship operator (#10251) (#4001)

* Fix cppcheckError with starship operator (#10251)

* Fix test case

* Return result
This commit is contained in:
chrchr-github 2022-04-13 12:23:38 +02:00 committed by GitHub
parent 6c82fb05a4
commit 5ac4afa5b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -111,6 +111,8 @@ R calculate(const std::string& s, const T& x, const T& y, bool* error = nullptr)
return wrap(x >= y);
case '<=':
return wrap(x <= y);
case '<=>':
return wrap(x - y);
}
throw InternalError(nullptr, "Unknown operator: " + s);
}

View File

@ -1075,6 +1075,13 @@ private:
ASSERT_EQUALS(22, values.back().intvalue);
}
// #10251 starship operator
code = "struct X {};\n"
"auto operator<=>(const X & a, const X & b) -> decltype(1 <=> 2) {\n"
" return std::strong_ordering::less;\n"
"}\n";
tokenValues(code, "<=>"); // don't throw
// Comparison of string
values = removeImpossible(tokenValues("f(\"xyz\" == \"xyz\");", "==")); // implementation defined
ASSERT_EQUALS(0U, values.size()); // <- no value