-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 C11/C++11 standard static assertion #12537
Conversation
I can probably convince myself that the first commit is correct, but
will refrain from approving because I don't feel expert enough.
Regarding the second commit, I have to say I don'treally see thepoint
because removing the macro makes itmandatory to specify an empty message
at each call site so I am not convinced we are gaininganything here?
|
Note that the empty message is mandatory in C11/C++11 but optional in C23/C++17. Not using |
OK, Iam convinced now, thanks! But jsut as a non-expert so I don't dare
to approve.
|
c13ab0d
to
3d1b637
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good to me. I'd be happy to get rid of the horrible definition of CAML_STATIC_ASSERT
that we currently use. A minor friction point is described below.
3d1b637
to
2cf4634
Compare
Remove CAML_STATIC_ASSERT, use static_assert directly. The assertions were moved to .c files as not to pollute the ocaml user-facing headers with includes of assert.h.
2cf4634
to
4304956
Compare
I've squashed the commits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me! Thanks.
A new step in my quest of pushing usage of standard C/C++ functions in OCaml… let's use the standard static assert mechanism. "old" versions of C/C++ require a message, newer versions don't. Prefer using a keyword instead of a macro, that's one fewer level of indirection. The error message is as clear as it gets.
static_assert
declaration (since C++11) (cppreference);static_assert
declaration (since C++11) (msvc).If we consider that all the compilers we support have full C11/C++11 support and are not buggy, we could remove the old code, or even use
static_assert
directly (as a macro for C11). The last commit does just that. If reviewers think it's too early to include it, I'll remove it from the PR. The macroCAML_STATIC_ASSERT
isn't used in any of the opam packages.