Fixinclude the header file <sys/ucred.h> that incorrectly uses the C-only _Atomic keyword when compiled as C++. Apply the same work-around for two GCC source files that transitively use this header file.
Index: fixincludes/inclhack.def =================================================================== --- fixincludes/inclhack.def (revision 270127) +++ fixincludes/inclhack.def (working copy) @@ -1298,6 +1298,36 @@ fix = { }; /* + * macOS 10.14.4 <sys/ucred.h> uses the C _Atomic keyword in C++ code. + */ +fix = { + hackname = darwin_ucred__Atomic; + mach = "*-*-darwin18.5.*"; + files = sys/ucred.h; + select = "_Atomic"; + + c_fix = wrap; + + c_fix_arg = <<- _EOArg_ + + #if defined(__cplusplus) && __cplusplus >= 201103L + # define _Atomic volatile + #endif + + _EOArg_; + + c_fix_arg = <<- _EOArg_ + + #if defined(__cplusplus) && __cplusplus >= 201103L + # undef _Atomic + #endif + + _EOArg_; + + test_text = "#include <sys/sysctl.h>\n"; +}; + +/* * For the AAB_darwin7_9_long_double_funcs fix to be useful, * you have to not use "" includes. */ Index: gcc/config/darwin-driver.c =================================================================== --- gcc/config/darwin-driver.c (revision 270127) +++ gcc/config/darwin-driver.c (working copy) @@ -27,7 +27,15 @@ along with GCC; see the file COPYING3. #include "diagnostic-core.h" #ifndef CROSS_DIRECTORY_STRUCTURE +#if defined(__cplusplus) && __cplusplus >= 201103L +// This is safe because it applies only to struct ucred, which is +// not actually used by gcc. +#define _Atomic volatile +#endif #include <sys/sysctl.h> +#if defined(__cplusplus) && __cplusplus >= 201103L +#undef _Atomic +#endif #include "xregex.h" static char * Index: libsanitizer/sanitizer_common/sanitizer_mac.cc =================================================================== --- libsanitizer/sanitizer_common/sanitizer_mac.cc (revision 270127) +++ libsanitizer/sanitizer_common/sanitizer_mac.cc (working copy) @@ -67,7 +67,13 @@ extern "C" { #include <sys/mman.h> #include <sys/resource.h> #include <sys/stat.h> +#if defined(__cplusplus) && __cplusplus >= 201103L +# define _Atomic volatile +#endif #include <sys/sysctl.h> +#if defined(__cplusplus) && __cplusplus >= 201103L +# undef _Atomic +#endif #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> -- Erik Schnetter <schnet...@gmail.com> http://www.perimeterinstitute.ca/personal/eschnetter/