Created
September 7, 2017 17:23
-
-
Save fxcoudert/f5c6a3b5ae61461c56ebeedb2dc2b56b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Header AvailabilityInternal.h cannot be processed by non-clang C compilers | |
Summary: Compiling C or C++ code with older, non-clang compilers (such as GCC 4.9 and older) leads to error in the system header AvailabilityInternal.h | |
The header features this line: | |
#if defined(__has_feature) && defined(__has_attribute) && __has_attribute(availability) | |
This is totally incorrect, because C preprocessor does not shortcircuit the && evaluation, and thus if the compiler does not have support for __has_feature, i.e. defined(__has_attribute) is 0, it will still call __has_attribute(availability) which results in an error. | |
The correct usage, which is used everywhere in this same header and in other system headers, is to split it into two separate preprocessor directives: | |
#if defined(__has_attribute) && defined(__has_feature) | |
#if __has_attribute(availability) | |
------ | |
Steps to Reproduce: Take a simple C source file that includes a system header, like this: | |
$ cat a.c | |
#include <stdlib.h> | |
Then compile it with a C compiler that does not support __has_attribute, such as GCC 4.9. | |
Expected Results: This should compile fine. | |
Actual Results: It crashes with this error: | |
/usr/include/AvailabilityInternal.h:25584:74: error: missing binary operator before token "(" | |
#if defined(__has_feature) && defined(__has_attribute) && __has_attribute(availability) | |
^ | |
Version/Build: macOS 10.13 beta 9 & Xcode 9 beta 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to compile ruby 1.8.7 in high sierra and faced the same issue. I solved it using C headers from my old sierra's backup.