Files
clang-p2996/clang/test/Modules/stddef.c
Ian Anderson 9a7a6dd3c3 [Modules] Make clang modules for the C standard library headers
Make top level modules for all the C standard library headers.

The `__stddef` implementation headers need header guards now that they're all modular. stdarg.h and stddef.h will be textual headers in the builtin modules, and so need to be repeatedly included in both the system and builtin module case. Define their header guards for consistency, but ignore them when building with modules.

`__stddef_null.h` needs to ignore its header guard when modules aren't being used to fulfill its redefinition obligation.
`__stddef_nullptr_t.h` needs to add a guard for C23 so that `_Builtin_stddef` can compile in C17 and earlier modes. `_Builtin_stddef.nullptr_t` can't require C23 because it also needs to be usable from C++.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D159064
2023-10-03 12:41:11 -07:00

30 lines
1.3 KiB
C

// RUN: rm -rf %t
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
// RUN: rm -rf %t
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
#include "ptrdiff_t.h"
ptrdiff_t pdt;
// size_t is declared in both size_t.h and __stddef_size_t.h, both of which are
// modular headers. Regardless of whether stddef.h joins the StdDef test module
// or is in its _Builtin_stddef module, __stddef_size_t.h will be in
// _Builtin_stddef.size_t. It's not defined which module will win as the expected
// provider of size_t. For the purposes of this test it doesn't matter which header
// gets reported, just as long as it isn't other.h or include_again.h.
size_t st; // expected-error-re {{missing '#include "{{size_t|__stddef_size_t}}.h"'; 'size_t' must be declared before it is used}}
// expected-note@size_t.h:* 0+ {{here}}
// expected-note@__stddef_size_t.h:* 0+ {{here}}
#include "include_again.h"
// Includes <stddef.h> which includes <__stddef_size_t.h> which imports the
// _Builtin_stddef.size_t module.
size_t st2;
#include "size_t.h"
// Redeclares size_t, but the type merger should figure it out.
size_t st3;