[libcxx] r249761 - Split <stddef.h> out of <cstddef>.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 8 15:25:27 PDT 2015


Author: rsmith
Date: Thu Oct  8 17:25:27 2015
New Revision: 249761

URL: http://llvm.org/viewvc/llvm-project?rev=249761&view=rev
Log:
Split <stddef.h> out of <cstddef>.

There are a bunch of macros (__need_size_t etc) that request just one piece of
<stddef.h>; if any one of these is defined, we just directly include the
underlying header.

Note that <stddef.h> provides a ::nullptr_t. We don't want that available to
includers of <cstddef>, so instead of following the usual pattern where <cfoo>
includes <foo.h> then pulls things from :: into std:: with using-declarations,
we implement <stddef.h> and <cstddef> separately; both include <__nullptr> for
the definition of std::nullptr_t.

Added:
    libcxx/trunk/include/stddef.h
      - copied, changed from r249737, libcxx/trunk/include/cstddef
Modified:
    libcxx/trunk/include/cstddef
    libcxx/trunk/test/std/depr/depr.c.headers/stddef_h.pass.cpp

Modified: libcxx/trunk/include/cstddef
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cstddef?rev=249761&r1=249760&r2=249761&view=diff
==============================================================================
--- libcxx/trunk/include/cstddef (original)
+++ libcxx/trunk/include/cstddef Thu Oct  8 17:25:27 2015
@@ -34,10 +34,10 @@ Types:
 */
 
 #include <__config>
+// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
+#include_next <stddef.h>
 #include <__nullptr>
 
-#include <stddef.h>
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif

Copied: libcxx/trunk/include/stddef.h (from r249737, libcxx/trunk/include/cstddef)
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/stddef.h?p2=libcxx/trunk/include/stddef.h&p1=libcxx/trunk/include/cstddef&r1=249737&r2=249761&rev=249761&view=diff
==============================================================================
--- libcxx/trunk/include/cstddef (original)
+++ libcxx/trunk/include/stddef.h Thu Oct  8 17:25:27 2015
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--------------------------- cstddef ----------------------------------===//
+//===--------------------------- stddef.h ---------------------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -8,20 +8,21 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _LIBCPP_CSTDDEF
-#define _LIBCPP_CSTDDEF
+#if defined(__need_ptrdiff_t) || defined(__need_size_t) || \
+    defined(__need_wchar_t) || defined(__need_NULL) || defined(__need_wint_t)
+#include_next <stddef.h>
+
+#elif !defined(_LIBCPP_STDDEF_H)
+#define _LIBCPP_STDDEF_H
 
 /*
-    cstddef synopsis
+    stddef.h synopsis
 
 Macros:
 
     offsetof(type,member-designator)
     NULL
 
-namespace std
-{
-
 Types:
 
     ptrdiff_t
@@ -29,31 +30,27 @@ Types:
     max_align_t
     nullptr_t
 
-}  // std
-
 */
 
 #include <__config>
-#include <__nullptr>
-
-#include <stddef.h>
+#include_next <stddef.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_BEGIN_NAMESPACE_STD
+#ifdef __cplusplus
 
-using ::ptrdiff_t;
-using ::size_t;
+extern "C++" {
+#include <__nullptr>
+using std::nullptr_t;
+}
 
-#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T)
 // Re-use the compiler's <stddef.h> max_align_t where possible.
-using ::max_align_t;
-#else
+#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T)
 typedef long double max_align_t;
 #endif
 
-_LIBCPP_END_NAMESPACE_STD
+#endif
 
-#endif  // _LIBCPP_CSTDDEF
+#endif  // _LIBCPP_STDDEF_H

Modified: libcxx/trunk/test/std/depr/depr.c.headers/stddef_h.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/stddef_h.pass.cpp?rev=249761&r1=249760&r2=249761&view=diff
==============================================================================
--- libcxx/trunk/test/std/depr/depr.c.headers/stddef_h.pass.cpp (original)
+++ libcxx/trunk/test/std/depr/depr.c.headers/stddef_h.pass.cpp Thu Oct  8 17:25:27 2015
@@ -10,6 +10,7 @@
 // <stddef.h>
 
 #include <stddef.h>
+#include <cassert>
 #include <type_traits>
 
 #ifndef NULL
@@ -22,6 +23,9 @@
 
 int main()
 {
+    void *p = NULL;
+    assert(!p);
+
     static_assert(sizeof(size_t) == sizeof(void*),
                   "sizeof(size_t) == sizeof(void*)");
     static_assert(std::is_unsigned<size_t>::value,
@@ -34,4 +38,22 @@ int main()
                   "std::is_signed<ptrdiff_t>::value");
     static_assert(std::is_integral<ptrdiff_t>::value,
                   "std::is_integral<ptrdiff_t>::value");
+    static_assert(std::is_same<decltype(nullptr), nullptr_t>::value,
+                  "decltype(nullptr) == nullptr_t");
+    static_assert(sizeof(nullptr_t) == sizeof(void*),
+                  "sizeof(nullptr_t) == sizeof(void*)");
+    static_assert(std::is_pod<max_align_t>::value,
+                  "std::is_pod<max_align_t>::value");
+    static_assert((std::alignment_of<max_align_t>::value >=
+                  std::alignment_of<long long>::value),
+                  "std::alignment_of<max_align_t>::value >= "
+                  "std::alignment_of<long long>::value");
+    static_assert(std::alignment_of<max_align_t>::value >=
+                  std::alignment_of<long double>::value,
+                  "std::alignment_of<max_align_t>::value >= "
+                  "std::alignment_of<long double>::value");
+    static_assert(std::alignment_of<max_align_t>::value >=
+                  std::alignment_of<void*>::value,
+                  "std::alignment_of<max_align_t>::value >= "
+                  "std::alignment_of<void*>::value");
 }




More information about the cfe-commits mailing list