https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116827

--- Comment #3 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
I thought the dependence on -fmodule-header was indicative of an issue with the
libstdc++ compatibility with the macOS SDK, but maybe I'm wrong. I've made it
component == target.

Looking at the macOS /usr/include/arm/_types.h header, in previous versions it
was defining __darwin_ptrdiff_t as:

----
#if defined(__PTRDIFF_TYPE__)
typedef __PTRDIFF_TYPE__        __darwin_ptrdiff_t;     /* ptr1 - ptr2 */
#elif defined(__LP64__)
typedef long                    __darwin_ptrdiff_t;     /* ptr1 - ptr2 */
#else
typedef int                     __darwin_ptrdiff_t;     /* ptr1 - ptr2 */
#endif /* __GNUC__ */
----

and now it is:

----
#if USE_CLANG_TYPES
typedef ptrdiff_t               __darwin_ptrdiff_t;     /* ptr1 - ptr2 */
#elif defined(__PTRDIFF_TYPE__)
typedef __PTRDIFF_TYPE__        __darwin_ptrdiff_t;     /* ptr1 - ptr2 */
#elif defined(__LP64__)
typedef long                    __darwin_ptrdiff_t;     /* ptr1 - ptr2 */
#else
typedef int                     __darwin_ptrdiff_t;     /* ptr1 - ptr2 */
#endif /* __GNUC__ */
----

where that new USE_CLANG_TYPES macro is defined at the top of the file:

----
#if defined(__has_feature) && __has_feature(modules)
#define USE_CLANG_TYPES 1
#else
#define USE_CLANG_TYPES 0
#endif

#if USE_CLANG_TYPES
#include <sys/_types/_ptrdiff_t.h>
#include <sys/_types/_size_t.h>
#include <sys/_types/_va_list.h>
#include <sys/_types/_wchar_t.h>
#endif
----

So -fmodule-header makes USE_CLANG_TYPES defined. Similarly,
/usr/include/sys/_types/_ptrdiff_t.h used to be relatively straightforward:

----
#ifndef _PTRDIFF_T
#define _PTRDIFF_T
#include <machine/types.h> /* __darwin_ptrdiff_t */
typedef __darwin_ptrdiff_t ptrdiff_t;
#endif /* _PTRDIFF_T */
----

but now it has more complex logic:

----
#if defined(__has_feature) && __has_feature(modules)
#define USE_CLANG_STDDEF 1
#else
#define USE_CLANG_STDDEF 0
#endif

#if USE_CLANG_STDDEF

#ifndef __PTRDIFF_T
#define __PTRDIFF_T

#define __need_ptrdiff_t
#include <stddef.h>
#undef __need_ptrdiff_t

#endif /* __PTRDIFF_T */

#else

#ifndef _PTRDIFF_T
#define _PTRDIFF_T
#include <machine/types.h> /* __darwin_ptrdiff_t */
typedef __darwin_ptrdiff_t ptrdiff_t;
#endif /* _PTRDIFF_T */

#endif
----

I'm thoroughly confused by this series of includes, especially as
__need_ptrdiff_t is never used anywhere in the SDK.

Reply via email to