Currently libc++'s stddef.h is treated as a textual header by the module map, and technically this is correct because the header is non-modular (at least during normal compilation).
Unfortunatly this means that the stddef module doesn't own any of the definitions it should, like size_t and ptrdiff_t. which end up getting owned by random STL headers.
Fortunately I believe that libc++'s stddef.h *is* modular due to Clang internals which handle modules containing stddef.h differently. Specifically Clang translates the module definition module stddef_h { header "stddef.h" export *} into
module stddef_h { textual header "clang/builtin-includes/.../stddef.h" header "libcxx/include/stddef.h" }
This means that the __need_* macros will always be resolved and #undef-ed by Clang's stddef.h header before processing libc++'s. Therefore we should be able to treat libc++'s header as non-textual. This allows libc++ to actually build a stddef_h module containing the correct definitions.
I've tested this change both with and without local sub-module visibility and on both Linux and OS X.
@rsmith What do you think? Does the above rational make sense?