<rdar://problem/13479214> Make Clang's <stddef.h> robust against system headers defining size_t/ptrdiff_t/wchar_t.

Clang's <stddef.h> provides definitions for the C standard library
types size_t, ptrdiff_t, and wchar_t. However, the system's C standard
library headers tend to provide the same typedefs, and the two
generally avoid each other using the macros
_SIZE_T/_PTRDIFF_T/_WCHAR_T. With modules, however, we need to see
*all* of the places where these types are defined, so provide the
typedefs (ignoring the macros) when modules are enabled.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177686 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2013-03-22 00:10:49 +00:00
Родитель f190f6b88e
Коммит daf2e1c636
5 изменённых файлов: 43 добавлений и 5 удалений

Просмотреть файл

@ -26,17 +26,28 @@
#ifndef __STDDEF_H #ifndef __STDDEF_H
#define __STDDEF_H #define __STDDEF_H
#ifndef _PTRDIFF_T #if !defined(_PTRDIFF_T) || __has_feature(modules)
/* Always define ptrdiff_t when modules are available. */
#if !__has_feature(modules)
#define _PTRDIFF_T #define _PTRDIFF_T
#endif
typedef __PTRDIFF_TYPE__ ptrdiff_t; typedef __PTRDIFF_TYPE__ ptrdiff_t;
#endif #endif
#ifndef _SIZE_T
#if !defined(_SIZE_T) || __has_feature(modules)
/* Always define size_t when modules are available. */
#if !__has_feature(modules)
#define _SIZE_T #define _SIZE_T
#endif
typedef __SIZE_TYPE__ size_t; typedef __SIZE_TYPE__ size_t;
#endif #endif
#ifndef __cplusplus #ifndef __cplusplus
#ifndef _WCHAR_T /* Always define wchar_t when modules are available. */
#if !defined(_WCHAR_T) || __has_feature(modules)
#if !__has_feature(modules)
#define _WCHAR_T #define _WCHAR_T
#endif
typedef __WCHAR_TYPE__ wchar_t; typedef __WCHAR_TYPE__ wchar_t;
#endif #endif
#endif #endif
@ -66,9 +77,12 @@ using ::std::nullptr_t;
/* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use /* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use
__WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */ __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
#if defined(__need_wint_t) #if defined(__need_wint_t)
#if !defined(_WINT_T) /* Always define wint_t when modules are available. */
#if !defined(_WINT_T) || __has_feature(modules)
#if !__has_feature(modules)
#define _WINT_T #define _WINT_T
#endif
typedef __WINT_TYPE__ wint_t; typedef __WINT_TYPE__ wint_t;
#endif /* _WINT_T */ #endif
#undef __need_wint_t #undef __need_wint_t
#endif /* __need_wint_t */ #endif /* __need_wint_t */

Просмотреть файл

@ -0,0 +1,11 @@
module StdDef {
module SizeT {
header "size_t.h"
export *
}
module Other {
header "other.h"
export *
}
}

Просмотреть файл

@ -0,0 +1,2 @@
#include <stddef.h>

Просмотреть файл

@ -0,0 +1,4 @@
#ifndef _SIZE_T
#define _SIZE_T
typedef __SIZE_TYPE__ size_t;
#endif

7
test/Modules/stddef.m Normal file
Просмотреть файл

@ -0,0 +1,7 @@
@import StdDef.Other;
size_t getSize();
// RUN: rm -rf %t
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
// expected-no-diagnostics