From: eregontp@... Date: 2021-03-27T11:43:38+00:00 Subject: [ruby-core:103059] [Ruby master Feature#17752] Enable -Wundef for C extensions in repository Issue #17752 has been updated by Eregon (Benoit Daloze). The `#if UNDEFINED_IDENTIFIER` seems fairly rare (56 vs 637), so it also seems more consistent to always use `#ifdef` if the identifier might not always be defined. One example is: ```c #if HAVE_RB_EXT_RACTOR_SAFE ``` vs ```c #ifdef HAVE_RB_EXT_RACTOR_SAFE ``` The second seems better to me, and is more explicit about the fact this might not be defined. The value of the macro ultimately does not matter for all `HAVE_` macros. ---------------------------------------- Feature #17752: Enable -Wundef for C extensions in repository https://bugs.ruby-lang.org/issues/17752#change-91120 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal ---------------------------------------- I would like to enable `-Wundef` for C extensions built/bundled with CRuby. From https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html > -Wundef > Warn if an undefined identifier is evaluated in an #if directive. Such identifiers are replaced with zero. I found this warning to be quite useful, notably when investigating why a given C extension did not include some code I expected, and then building those extensions on TruffleRuby. There are a couple places not respecting this currently but they seem trivial to fix, I can do that. For instance a confusing case is: https://github.com/ruby/ruby/blob/9143d21b1bf2f16b1e847d569a588510726d8860/ext/nkf/nkf-utf8/nkf.h#L19 ``` #if DEFAULT_NEWLINE == 0x0D0A ``` which without -Wundef would just exclude the code without any warning if DEFAULT_NEWLINE is not defined. I'm not sure if we should/can enable it for C extensions in general (installed as gems), as if a C extensions uses -Werror and would have such a warning it would no longer build. I can make a PR for this. I'm not sure where to add -Wundef though, should it be in https://github.com/ruby/ruby/blob/9143d21b1bf2f16b1e847d569a588510726d8860/configure.ac#L620, or maybe in mkmf.rb? -- https://bugs.ruby-lang.org/ Unsubscribe: