Clang fails to compile code that works with gcc on windows due to wint_t not defined


I am trying to use clang to compile a very simple hello world on Windows
and compilation is failing due to wint_t not being defined.

Here are the particulars of my environment, I am trying it on Cygwin,
with versions of llvm & clang that are a couple days old. I've checked
out the copies and manually compiled and installed them on Cygwin (so
they are not native Windows builds).

After tracing through the header files I came to the fragments that
actually define wint_t:

From Gcc's stddef.h:

#if defined (__need_wint_t)
#ifndef _WINT_T
#define _WINT_T

#ifndef __WINT_TYPE__
#define __WINT_TYPE__ unsigned int
typedef __WINT_TYPE__ wint_t;
#undef __need_wint_t

In clang's stddef.h, the equivalent is:

// Some C libraries expect to see a wint_t here. Others (notably MinGW)
will use
// __WINT_TYPE__ directly; accomodate both by requiring __need_wint_t
#if defined(__need_wint_t) && !defined(_WINT_T)
#define _WINT_T
typedef __WINT_TYPE__ wint_t;

Now, what's happening is that through the inclusion chain, Gcc's
stddef.h is included multiple times, each time sort of enabling an extra
part of the file, while clang's stddef.h is included only once at the
very beginning through stdio.h before __need_wint_t is defined. Later on
when __need_wint_t actually gets defined and stddef.h is included again,
the guard directive prevents it from being read and thus wint_t never
gets defined.

I'm not sure what's the best way to solve this problem. I do not want to
go and start locally hacking the include files, I know they will change
down the road and thus whatever will compile after my hacks will break
again in the future.

I have attached the following formatted patch, if you guys think that's
a valid solution, I'll go ahead and send if to the cfe-commits list for

+#if (!defined(__STDDEF_H) || defined(__need_wint_t))
#ifndef __STDDEF_H
#define __STDDEF_H


stddef.h.patch (442 Bytes)