-
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
Warn if an undefined identifier is evaluated in an #if
directive (enable -Wundef
)
#12714
Conversation
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.
Sounds reasonable to me, and a trivial change.
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.
I'm not convinced that the (standard-conformant usage) of giving undefined macros the "0" value for numerical comparison purposes is bad. Yes, Clang and perhaps GCC have -Wundef
to warn about it, but they also have other warnings that we don't care about for the OCaml code base and include files.
On the other hand, the proposed changes to please -Wundef
are rather small, and can be made smaller (see comments below), so I can go along with this PR.
Thanks all for the reviews.
This change was specially to satisfy GCC users who'd write C++ or Objective-C code, include caml headers, and define $ g++ -Wundef -x c++ -c - <<'EOF'
#ifdef __STDC_VERSION__
#warning stdc-version-defined
#else
#warning stdc-version-undefined
#endif
EOF
<stdin>:4:2: warning: #warning stdc-version-undefined [-Wcpp] (this is also the case in |
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.
Possible alternate way of expressing the change in gethost.c
with a minor tidy-up.
In case users apply the -Wundef flag on their own C code.
I think that the changes are small enough that merging them now is less work than explaining to people in the future what we think about
|
I'm not strongly opposed to merging this PR, just a bit skeptical about the actual usefulness. Searching for https://www.gnu.org/prep/standards/html_node/Syntactic-Conventions.html#Syntactic-Conventions
|
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.
I think it's a reasonable goal to support users being able to build their code with -Wundef
and not have the public (i.e. non-CAML_INTERNALS
) parts of our headers trigger that warning. If we're supporting that goal, then I very much like being able to continuously ensure that we aren't breaking it (i.e. the adding of -Wundef
to the development mode flags).
An alternative would be to use the appropriate #pragma
s to turn off the warning in our own C files, but I agree with #12714 (review) that the places affected are so few that this looks like the easiest way of doing it.
Thanks, @MisterDA!
One small thing I find this macro useful for is that I may have missed a header or a particular condition to enable features from a header. // say I get this wrong
#define _WIN32_WINNT 0xBAD
// or I forget this
#include <stdheader.h>
// but I need them for this function call
int flags = THIS_WEIRD_FLAG;
f(THIS_WEIRD_FLAG); Without #ifndef THIS_WEIRD_FLAG
#error "somethings's fishy"
#endif otherwise as noted the preproc would have silently replaced the weird flag with But with |
#if
directive (enable -Wundef
)
#else | ||
#define Reserved_space_c_stack_link 0 | ||
#endif |
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.
I agree the code is cleaner this way.
All right, that's enough good reasons to go in the direction of this PR. Merging right now! |
Prior art in #11263 and #11267.
Reserved_space_c_stack_link
after its sole use infiber.h
? It's not even namespaced.-Wundef
to our internal flags to prevent this error from happening again. It applies to public headers (good!) and internal files (bad?).macintosh
macro had been forgotten during the removal of Mac OS 9…I've tested this change with gcc, mingw-w64 (gcc), and g++ on a stub file including all the
caml/
headers.