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

Use sizeof(T) == 0 instead of always_false #740

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jmcarcell
Copy link
Member

@jmcarcell jmcarcell commented Feb 19, 2025

Introduced in #737 (also see #736 (comment)) I think it is not necessary to add that and the included header can be removed.

This is turbo pedantic but

Sorry :(

BEGINRELEASENOTES

  • Use sizeof(T) == 0 instead of always_false

ENDRELEASENOTES

@m-fila
Copy link
Contributor

m-fila commented Feb 19, 2025

In my defense P2593R1 (accepted for C++23) where relaying on sizeof(T) is explicitly listed as being wrong. But I agree in the end it doesn't really matter. We could also go back to sizeof(T) == 0

@jmcarcell
Copy link
Member Author

Ah I didn't get that it was static_assert(false) what wasn't compiling, I thought it was sizeof(T) == 0

@m-fila
Copy link
Contributor

m-fila commented Feb 19, 2025

Yeah, sizeof(T) && false, sizeof(T) == 0 and always_false are workarounds for static_assert(false) not behaving as desired. It's just that according to the standard always_false actually works, while the rest work by accident on most of the compilers

@jmcarcell jmcarcell changed the title Use sizeof(T) && false instead of always_false Use sizeof(T) == 0 instead of always_false Feb 20, 2025
@tmadlener
Copy link
Collaborator

Given that the current always_false is a workaround for static_assert(false) only starting to work as expected in c++23. I would be in favor of keeping always_false because it's very clear in its name, whereas sizeof(T) == 0 needs some a bit more knowledge about why it is there.

@jmcarcell
Copy link
Member Author

I don't have a strong opinion about this one. My preference would be not to include something that may or not be removed when switching to C++23 when there is already a (simple) way. So feel free to do whatever you want with this PR.

@m-fila
Copy link
Contributor

m-fila commented Feb 28, 2025

My preference would be not to include something that may or not be removed when switching to C++23 when there is already a (simple) way.

Whichever workaround we choose now with C++23 we can replace it with static_assert(false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants