Fix conditional inclusion of stdckdint.h#531
Conversation
Because `__has_include` is on a `#elif` line, it is still being evaluated by the pre-processor regardless of `#if defined`, even if not executed. It must exist on its own gated level inside of the `#if` block rather than at the same level as the `#if` block to function correctly. This fixes a compilation error on a platform which doesn't have `__has_include` available.
|
cc @jhawthorn |
Can you provide a platform or a code example that describe the compilation error? The code below passes compile, so I think there's no compilation problem. #define EXISTING_MACRO
#if defined(EXISTING_MACRO) || !defined(__nonexistent_preprocessor_operator)
#elif __nonexistent_preprocessor_operator(<stdckdint.h>)
# define EXISTING_MACRO 1
#endif
#if defined(NONEXISTENT_MACRO) || !defined(__nonexistent_preprocessor_operator)
#elif __nonexistent_preprocessor_operator(<stdckdint.h>)
# define NONEXISTENT_MACRO 1
#endifMy understanding is: #if defined(HAVE_STDCKDINT_H) || !defined(__has_include)
// Evaluated if HAVE_STDCKDINT_H already defined OR __has_include is not defined.
// So elif condition is evaluated as negation of this: HAVE_STDCKDINT_H not defined AND __has_include defined
#elif __has_include(<stdckdint.h>)
# define HAVE_STDCKDINT_H 1
#endifLet me know if my understanding is wrong. |
| #elif __has_include(<stdckdint.h>) | ||
| #if !defined(HAVE_STDCKDINT_H) | ||
| #if defined(__has_include) | ||
| #if __has_include(<stdckdint.h>) |
There was a problem hiding this comment.
The original empty-if plus elif is not so readable, and there's a room improvement. But triple-nested-if is also not so good.
It's worth merging this as a refactoring even if there's no compilation problem in the original code.
#if cod1 && cond2 && cond3 may be better than tripple-nested-if and also better than empty-if plus elif. What do you think?
There was a problem hiding this comment.
Sorry, this file dtoa.c is a copy of https://github.com/ruby/ruby/blob/master/missing/dtoa.c. It was recently updated to the latest one.
I don't want to add a difference because updating the file might be difficult in the future.
|
This file |
|
Rather than close this PR, how about we re-open this, get the upstream core Ruby file fixed and this one too? This is actively failing compilation on compilers that dont have the |
|
The very thing the conditional for `__has_include` is trying to handle, is causing compilation to break. This file was brought into the ruby/bigdecimal project, and is failing to compile on a platform which doesnt have `__has_include` support in the compiler. Compile log can be found in this comment: ruby/bigdecimal#531 (comment)
|
I see, so the cause is not only the existence of By the way, I think it's worth adding a description/commit message to ruby/ruby#16802 that mention about |
Because
__has_includeis on a#elifline, it is still being evaluated by the pre-processor regardless of#if defined, even if not executed. It must exist on its own gated level inside of the#ifblock rather than at the same level as the#ifblock to function correctly.This fixes a compilation error on a platform which doesn't have
__has_includeavailable.