[libc++] Clean up tests for "optional" C11 features
authorLouis Dionne <ldionne@apple.com>
Tue, 28 Jul 2020 17:41:12 +0000 (13:41 -0400)
committerLouis Dionne <ldionne@apple.com>
Tue, 28 Jul 2020 19:13:05 +0000 (15:13 -0400)
First, add a TEST_HAS_QUICK_EXIT macro to mirror other C11 features like
TEST_HAS_ALIGNED_ALLOC, and update the tests for that.

Second, get rid of TEST_HAS_C11_FEATURES and _LIBCPP_HAS_C11_FEATURES,
which were only used to ensure that feature macros don't get out of
sync between <__config> and "test_macros.h". This is not necessary
anymore, since we have tests for each individual macro now.

12 files changed:
libcxx/include/__config
libcxx/test/libcxx/language.support/has_aligned_alloc.compile.pass.cpp [new file with mode: 0644]
libcxx/test/libcxx/language.support/has_c11_features.pass.cpp [deleted file]
libcxx/test/libcxx/language.support/has_quick_exit.compile.pass.cpp [new file with mode: 0644]
libcxx/test/libcxx/language.support/has_timespec_get.compile.pass.cpp [new file with mode: 0644]
libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
libcxx/test/std/language.support/support.start.term/at_quick_exit.compile.fail.cpp [moved from libcxx/test/std/language.support/support.start.term/quick_exit_check1.compile.fail.cpp with 70% similarity]
libcxx/test/std/language.support/support.start.term/quick_exit.compile.fail.cpp [moved from libcxx/test/std/language.support/support.start.term/quick_exit_check2.compile.fail.cpp with 72% similarity]
libcxx/test/std/language.support/support.start.term/quick_exit.pass.cpp
libcxx/test/support/msvc_stdlib_force_include.h
libcxx/test/support/test_macros.h

index ebdd64e..a9eca04 100644 (file)
 #  if defined(__FreeBSD__)
 #    define _LIBCPP_HAS_ALIGNED_ALLOC
 #    define _LIBCPP_HAS_QUICK_EXIT
-#    define _LIBCPP_HAS_C11_FEATURES
 #    if __FreeBSD_version >= 1300064 || \
        (__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)
 #      define _LIBCPP_HAS_TIMESPEC_GET
 #    endif
 #  elif defined(__BIONIC__)
-#    define _LIBCPP_HAS_C11_FEATURES
 #    if __ANDROID_API__ >= 21
 #      define _LIBCPP_HAS_QUICK_EXIT
 #    endif
 #    define _LIBCPP_HAS_ALIGNED_ALLOC
 #    define _LIBCPP_HAS_QUICK_EXIT
 #    define _LIBCPP_HAS_TIMESPEC_GET
-#    define _LIBCPP_HAS_C11_FEATURES
 #  elif defined(__linux__)
 #    if !defined(_LIBCPP_HAS_MUSL_LIBC)
 #      if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
 #      endif
 #      if _LIBCPP_GLIBC_PREREQ(2, 17)
 #        define _LIBCPP_HAS_ALIGNED_ALLOC
-#        define _LIBCPP_HAS_C11_FEATURES
 #        define _LIBCPP_HAS_TIMESPEC_GET
 #      endif
 #    else // defined(_LIBCPP_HAS_MUSL_LIBC)
 #      define _LIBCPP_HAS_ALIGNED_ALLOC
 #      define _LIBCPP_HAS_QUICK_EXIT
 #      define _LIBCPP_HAS_TIMESPEC_GET
-#      define _LIBCPP_HAS_C11_FEATURES
 #    endif
 #  endif // __linux__
 #endif
diff --git a/libcxx/test/libcxx/language.support/has_aligned_alloc.compile.pass.cpp b/libcxx/test/libcxx/language.support/has_aligned_alloc.compile.pass.cpp
new file mode 100644 (file)
index 0000000..d1b41de
--- /dev/null
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// Make sure TEST_HAS_ALIGNED_ALLOC (defined by the test suite) and
+// _LIBCPP_HAS_ALIGNED_ALLOC (defined by libc++) stay in sync.
+
+#include <__config>
+#include "test_macros.h"
+
+#if defined(TEST_HAS_ALIGNED_ALLOC) != defined(_LIBCPP_HAS_ALIGNED_ALLOC)
+#   error "TEST_HAS_ALIGNED_ALLOC and _LIBCPP_HAS_ALIGNED_ALLOC are out of sync"
+#endif
diff --git a/libcxx/test/libcxx/language.support/has_c11_features.pass.cpp b/libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
deleted file mode 100644 (file)
index ab1e6ea..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03, c++11, c++14
-
-//     We have two macros for checking whether or not the underlying C library
-//      has C11 features:
-//             TEST_HAS_C11_FEATURES    - which is defined in "test_macros.h"
-//             _LIBCPP_HAS_C11_FEATURES - which is defined in <__config>
-//     They should always be the same
-
-#include <__config>
-#include "test_macros.h"
-
-#ifdef TEST_HAS_C11_FEATURES
-# ifndef _LIBCPP_HAS_C11_FEATURES
-#  error "TEST_HAS_C11_FEATURES is defined, but _LIBCPP_HAS_C11_FEATURES is not"
-# endif
-#endif
-
-#ifdef _LIBCPP_HAS_C11_FEATURES
-# ifndef TEST_HAS_C11_FEATURES
-#  error "_LIBCPP_HAS_C11_FEATURES is defined, but TEST_HAS_C11_FEATURES is not"
-# endif
-#endif
-
-int main(int, char**) {
-  return 0;
-}
diff --git a/libcxx/test/libcxx/language.support/has_quick_exit.compile.pass.cpp b/libcxx/test/libcxx/language.support/has_quick_exit.compile.pass.cpp
new file mode 100644 (file)
index 0000000..ad0fe6f
--- /dev/null
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// Make sure TEST_HAS_QUICK_EXIT (defined by the test suite) and
+// _LIBCPP_HAS_QUICK_EXIT (defined by libc++) stay in sync.
+
+#include <__config>
+#include "test_macros.h"
+
+#if defined(TEST_HAS_QUICK_EXIT) != defined(_LIBCPP_HAS_QUICK_EXIT)
+#   error "TEST_HAS_QUICK_EXIT and _LIBCPP_HAS_QUICK_EXIT are out of sync"
+#endif
diff --git a/libcxx/test/libcxx/language.support/has_timespec_get.compile.pass.cpp b/libcxx/test/libcxx/language.support/has_timespec_get.compile.pass.cpp
new file mode 100644 (file)
index 0000000..8b86a5e
--- /dev/null
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// Make sure TEST_HAS_TIMESPEC_GET (defined by the test suite) and
+// _LIBCPP_HAS_TIMESPEC_GET (defined by libc++) stay in sync.
+
+#include <__config>
+#include "test_macros.h"
+
+#if defined(TEST_HAS_TIMESPEC_GET) != defined(_LIBCPP_HAS_TIMESPEC_GET)
+#   error "TEST_HAS_TIMESPEC_GET and _LIBCPP_HAS_TIMESPEC_GET are out of sync"
+#endif
index 779fbc6..1069a67 100644 (file)
@@ -24,7 +24,7 @@
 #error FLT_RADIX not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_HAS_SUBNORM
 #error FLT_HAS_SUBNORM not defined
 #endif
@@ -54,7 +54,7 @@
 #error DECIMAL_DIG not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_DECIMAL_DIG
 #error FLT_DECIMAL_DIG not defined
 #endif
 #error LDBL_MIN not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_TRUE_MIN
 #error FLT_TRUE_MIN not defined
 #endif
index 12b80ad..6ddd8c6 100644 (file)
@@ -24,7 +24,7 @@
 #error FLT_RADIX not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_HAS_SUBNORM
 #error FLT_HAS_SUBNORM not defined
 #endif
@@ -54,7 +54,7 @@
 #error DECIMAL_DIG not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_DECIMAL_DIG
 #error FLT_DECIMAL_DIG not defined
 #endif
 #error LDBL_MIN not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_TRUE_MIN
 #error FLT_TRUE_MIN not defined
 #endif
@@ -5,23 +5,23 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-//
+
 // UNSUPPORTED: c++03
 
-// test that referencing at_quick_exit when _LIBCPP_HAS_QUICK_EXIT is not defined
+// test that referencing at_quick_exit when TEST_HAS_QUICK_EXIT is not defined
 // results in a compile error.
 
 #include <cstdlib>
 
-void f() {}
+#include "test_macros.h"
 
-int main(int, char**)
-{
-#ifndef _LIBCPP_HAS_QUICK_EXIT
+void f() { }
+
+int main(int, char**) {
+#if !defined(TEST_HAS_QUICK_EXIT)
     std::at_quick_exit(f);
 #else
-#error
+#   error
 #endif
-
-  return 0;
+    return 0;
 }
@@ -5,22 +5,21 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+
 // UNSUPPORTED: c++03
 
-// test that referencing quick_exit when _LIBCPP_HAS_QUICK_EXIT is not defined
+// test that referencing quick_exit when TEST_HAS_QUICK_EXIT is not defined
 // results in a compile error.
 
 #include <cstdlib>
 
-void f() {}
+#include "test_macros.h"
 
-int main(int, char**)
-{
-#ifndef _LIBCPP_HAS_QUICK_EXIT
+int main(int, char**) {
+#if !defined(TEST_HAS_QUICK_EXIT)
     std::quick_exit(0);
 #else
-#error
+#   error
 #endif
-
-  return 0;
+    return 0;
 }
index b45b339..16f68d4 100644 (file)
@@ -17,7 +17,7 @@ void f() {}
 
 int main(int, char**)
 {
-#ifdef _LIBCPP_HAS_QUICK_EXIT
+#ifdef TEST_HAS_QUICK_EXIT
     std::at_quick_exit(f);
     std::quick_exit(0);
 #endif
index cf8696a..0869be3 100644 (file)
@@ -65,9 +65,6 @@ const AssertionDialogAvoider assertion_dialog_avoider{};
 // MSVC doesn't have __int128_t.
 #define _LIBCPP_HAS_NO_INT128
 
-// MSVC has quick_exit() and at_quick_exit().
-#define _LIBCPP_HAS_QUICK_EXIT
-
 #ifndef _LIBCXX_IN_DEVCRT
     // atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
     #define _ENABLE_ATOMIC_ALIGNMENT_FIX
index 63aa4f4..15c6a28 100644 (file)
 //  Specifically, FreeBSD does NOT have timespec_get, even though they have all
 //  the rest of C11 - this is PR#38495
 #    define TEST_HAS_ALIGNED_ALLOC
-#    define TEST_HAS_C11_FEATURES
+#    define TEST_HAS_QUICK_EXIT
 #  elif defined(__BIONIC__)
-#    define TEST_HAS_C11_FEATURES
+#    if __ANDROID_API__ >= 21
+#      define TEST_HAS_QUICK_EXIT
+#    endif
 #    if __ANDROID_API__ >= 28
 #      define TEST_HAS_ALIGNED_ALLOC
 #    endif
 #      define TEST_HAS_TIMESPEC_GET
 #    endif
 #  elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
+#    define TEST_HAS_QUICK_EXIT
 #    define TEST_HAS_ALIGNED_ALLOC
-#    define TEST_HAS_C11_FEATURES
 #    define TEST_HAS_TIMESPEC_GET
 #  elif defined(__linux__)
 // This block preserves the old behavior used by include/__config:
 // available. The configuration here may be too vague though, as Bionic, uClibc,
 // newlib, etc may all support these features but need to be configured.
 #    if defined(TEST_GLIBC_PREREQ)
+#      if TEST_GLIBC_PREREQ(2, 15)
+#        define TEST_HAS_QUICK_EXIT
+#      endif
 #      if TEST_GLIBC_PREREQ(2, 17)
 #        define TEST_HAS_ALIGNED_ALLOC
 #        define TEST_HAS_TIMESPEC_GET
-#        define TEST_HAS_C11_FEATURES
 #      endif
 #    elif defined(_LIBCPP_HAS_MUSL_LIBC)
+#      define TEST_HAS_QUICK_EXIT
 #      define TEST_HAS_ALIGNED_ALLOC
-#      define TEST_HAS_C11_FEATURES
 #      define TEST_HAS_TIMESPEC_GET
 #    endif
 #  elif defined(_WIN32)
 #    if defined(_MSC_VER) && !defined(__MINGW32__)
+#      define TEST_HAS_QUICK_EXIT
 #      define TEST_HAS_ALIGNED_ALLOC
-#      define TEST_HAS_C11_FEATURES // Using Microsoft's C Runtime library
 #      define TEST_HAS_TIMESPEC_GET
 #    endif
 #  endif