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
<compare>: std::_Literal_zero
has an impact on real code.
#4359
Comments
It's unfortunate that [cmp.categories.pre]/3 doesn't seem to limit the evilness of the unspecified parameter type... |
It sure looks like this is an MSVC compiler
#include <compare>
template <typename T, typename U>
constexpr bool not_equal(T lhs, U rhs)
requires (requires(T lhs, U rhs) { lhs != rhs; })
{
return lhs != rhs;
}
int main() {
constexpr int int_zero = 0;
constexpr auto ordering = 1 <=> 1;
constexpr bool b = not_equal(ordering, int_zero);
return b == false;
}
|
Oh, I think this is probably because of that MSVC hasn't implemented WG21-P2564R3 (DR against C++20). Reduced example (Godbolt link): struct Par {
consteval Par(int) {}
};
template<class I>
constexpr bool testfun(I n)
{
(void) Par{n};
return true;
}
int main()
{
static_assert(testfun(0));
}
Until P2564R3, the immediate function call is required to produce a constant expression, while reading from a function parameter makes the function call non-constant, which would in turn results in compilation error. |
Yeah, I am not happy about not being able to SFINAE on the type, but after MSVC implements P2564 I can solve my issue by constexprifying the relevant parts of Catch2. |
I found a Devcom issue about P2564R3: Devcom-10514467 |
Hello @cdacamar , sorry to bother you, but could you please let me know if the implementation of P2564R3 is in your team near plans or if you are currently busy with other work and the implementation is not planned for the near future? You can respond here or in the Devcom-10514467. Thank you in advance! |
I can't provide any specifics as to when this DR will be implemented, but since it was approved in Kona in 2022 we have been tracking it as part of our upcoming C++23 work. I expect us to start work on C++23 stuff very soon. For STL maintainers with internal query access, the User Story for the feature is VSO-1676035. |
That was pretty mind bending to implement, good luck :D |
Hello, I have a problem.
the _Literal_zero_is_expected function is used as an exported function.
I found the following information
Does it mean that this code is not 0(_Zero != 0), causing a link error?
|
Please give me your full example.
A link error should be only for wrong code. That's the idea of the |
The body of a |
I compiled a latest version of llvm, from the main branch, also encountered the same problem
Have you compiled the latest chromium on windows, after pulling the main branch, you can compile with the following parameters
During the compilation process, you may encounter some compilation errors, but this does not affect the reproduction of this problem
Then find a function similar to this
You can see that the function(_Literal_zero_is_expected) is referenced In addition, when I want to write a demo to reproduce this problem using base::TimeDelta and base::ClampedNumeric, but the generated code does not introduce _Literal_zero_is_expected(using the same version of clang)
chromium:
|
I think it may be due to a clang option added by chromium |
Describe the bug
Our type
std::_Literal_zero
has an impact on real code.From the comment: #4332 (comment)
Command-line test case
Expected behavior
Should compile
STL version
202e382
Additional context
Other compiler libraries compile the code: https://godbolt.org/z/1vbYbq5b7
We added
std::_Literal_zero
because of this issue: #3581Previously
using _Literal_zero = decltype(nullptr);
warned this code:The text was updated successfully, but these errors were encountered: