Skip to content

Implement sizeof<T> #574

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

Closed
wants to merge 3 commits into from
Closed

Implement sizeof<T> #574

wants to merge 3 commits into from

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Aug 6, 2023

Fix sizeof/new hints with parentheses.
Fixes #566.

@JohelEGP
Copy link
Contributor

JohelEGP commented Aug 6, 2023

Thank you for doing this!
I wouldn't have thought that sizeof was supposed to work with <>.
However, it doesn't seem to work (https://cpp2.godbolt.org/z/K8nPMeaa4):

main: () -> int = sizeof<i32>;
[[nodiscard]] auto main() -> int { return sizeof<cpp2::i32>;  }
main.cpp2: In function 'int main()':
main.cpp2:1:49: error: expected primary-expression before '<' token
main.cpp2:1:59: error: expected primary-expression before '>' token
main.cpp2:1:60: error: expected primary-expression before ';' token

@ntrel
Copy link
Contributor Author

ntrel commented Aug 6, 2023

@JohelEGP You're right, I heard it would use <> but there are passthrough-tests that use it with parentheses. I'll have a look.

Update: turns out they were not pure cpp2.

@ntrel
Copy link
Contributor Author

ntrel commented Aug 6, 2023

@JohelEGP I think it wasn't implemented. sizeof<i32> should work now.

@ntrel ntrel changed the title Fix sizeof/new hints with parentheses Implement sizeof<T> Aug 6, 2023
@hsutter
Copy link
Owner

hsutter commented Aug 10, 2023

Thanks but I think this is fixed with the commit that closed #566.

I see the consistency of using < > for sizeof as well as new, but in Cpp2 the type passed to new really is a template argument and I didn't see a reason to change from the familiar function-like syntax sizeof(thing) to sizeof<thing> ...? I was thinking of sizeof as a constexpr function for which ( ) would be fine.

I'll close this for now as the other commit addressed #566, but feel free to open a new issue if you want to provide rationale for changing sizeof(thing) to sizeof<thing> (e.g., what problems does it solve, the usual questions).

Thanks!

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.

[BUG] Can't use sizeof
3 participants