[libcxx] cleans up __cpp_concepts mess
authorChristopher Di Bella <cjdb@google.com>
Fri, 19 Feb 2021 01:54:52 +0000 (01:54 +0000)
committerChristopher Di Bella <cjdb@google.com>
Fri, 26 Feb 2021 18:43:40 +0000 (18:43 +0000)
libc++ was previously a bit confused by what the value of __cpp_concepts
should be. Also replaces `__floating_point` with `floating_point` now
that it exists.

Differential Revision: https://reviews.llvm.org/D97015

libcxx/include/concepts
libcxx/include/numbers
libcxx/include/random
libcxx/include/version
libcxx/test/std/language.support/support.limits/support.limits.general/numbers.version.pass.cpp
libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp
libcxx/utils/generate_feature_test_macro_components.py
libcxx/utils/libcxx/test/features.py

index dac6b69..3d57c40 100644 (file)
@@ -149,7 +149,7 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 // [concept.same]
 
@@ -228,7 +228,7 @@ concept invocable = requires(_Fn&& __fn, _Args&&... __args) {
 template<class _Fn, class... _Args>
 concept regular_invocable = invocable<_Fn, _Args...>;
 
-#endif // _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD
 
index 38dad99..e5172af 100644 (file)
@@ -60,8 +60,9 @@ namespace std::numbers {
 
 #include <__config>
 
-#if _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
+#include <concepts>
 #include <type_traits>
 #include <version>
 
@@ -99,22 +100,19 @@ template <class T> inline constexpr T inv_sqrt3_v =  __illformed<T>{};
 template <class T> inline constexpr T egamma_v =     __illformed<T>{};
 template <class T> inline constexpr T phi_v =        __illformed<T>{};
 
-template <class T>
-concept __floating_point = is_floating_point_v<T>;
-
-template <__floating_point T> inline constexpr T e_v<T>          = 2.718281828459045235360287471352662;
-template <__floating_point T> inline constexpr T log2e_v<T>      = 1.442695040888963407359924681001892;
-template <__floating_point T> inline constexpr T log10e_v<T>     = 0.434294481903251827651128918916605;
-template <__floating_point T> inline constexpr T pi_v<T>         = 3.141592653589793238462643383279502;
-template <__floating_point T> inline constexpr T inv_pi_v<T>     = 0.318309886183790671537767526745028;
-template <__floating_point T> inline constexpr T inv_sqrtpi_v<T> = 0.564189583547756286948079451560772;
-template <__floating_point T> inline constexpr T ln2_v<T>        = 0.693147180559945309417232121458176;
-template <__floating_point T> inline constexpr T ln10_v<T>       = 2.302585092994045684017991454684364;
-template <__floating_point T> inline constexpr T sqrt2_v<T>      = 1.414213562373095048801688724209698;
-template <__floating_point T> inline constexpr T sqrt3_v<T>      = 1.732050807568877293527446341505872;
-template <__floating_point T> inline constexpr T inv_sqrt3_v<T>  = 0.577350269189625764509148780501957;
-template <__floating_point T> inline constexpr T egamma_v<T>     = 0.577215664901532860606512090082402;
-template <__floating_point T> inline constexpr T phi_v<T>        = 1.618033988749894848204586834365638;
+template <floating_point T> inline constexpr T e_v<T>          = 2.718281828459045235360287471352662;
+template <floating_point T> inline constexpr T log2e_v<T>      = 1.442695040888963407359924681001892;
+template <floating_point T> inline constexpr T log10e_v<T>     = 0.434294481903251827651128918916605;
+template <floating_point T> inline constexpr T pi_v<T>         = 3.141592653589793238462643383279502;
+template <floating_point T> inline constexpr T inv_pi_v<T>     = 0.318309886183790671537767526745028;
+template <floating_point T> inline constexpr T inv_sqrtpi_v<T> = 0.564189583547756286948079451560772;
+template <floating_point T> inline constexpr T ln2_v<T>        = 0.693147180559945309417232121458176;
+template <floating_point T> inline constexpr T ln10_v<T>       = 2.302585092994045684017991454684364;
+template <floating_point T> inline constexpr T sqrt2_v<T>      = 1.414213562373095048801688724209698;
+template <floating_point T> inline constexpr T sqrt3_v<T>      = 1.732050807568877293527446341505872;
+template <floating_point T> inline constexpr T inv_sqrt3_v<T>  = 0.577350269189625764509148780501957;
+template <floating_point T> inline constexpr T egamma_v<T>     = 0.577215664901532860606512090082402;
+template <floating_point T> inline constexpr T phi_v<T>        = 1.618033988749894848204586834365638;
 
 inline constexpr double e          = e_v<double>;
 inline constexpr double log2e      = log2e_v<double>;
@@ -136,6 +134,6 @@ _LIBCPP_END_NAMESPACE_STD
 
 _LIBCPP_POP_MACROS
 
-#endif //_LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
+#endif //_LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 #endif // _LIBCPP_NUMBERS
index 1cbe9b5..a2f45ba 100644 (file)
@@ -1701,7 +1701,7 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 // [rand.req.urng]
 template<class _Gen>
@@ -1713,7 +1713,7 @@ concept uniform_random_bit_generator =
     requires bool_constant<(_Gen::min() < _Gen::max())>::value;
   };
 
-#endif // _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 // __is_seed_sequence
 
index 3252219..e869723 100644 (file)
@@ -336,7 +336,7 @@ __cpp_lib_void_t                                        201411L <type_traits>
 #   define __cpp_lib_latch                              201907L
 # endif
 # define __cpp_lib_list_remove_return_type              201806L
-# if defined(__cpp_concepts) && __cpp_concepts >= 201811L
+# ifndef _LIBCPP_HAS_NO_CONCEPTS
 #   define __cpp_lib_math_constants                     201907L
 # endif
 // # define __cpp_lib_polymorphic_allocator                201902L
index 9e6b1fa..aaa64d1 100644 (file)
@@ -42,7 +42,7 @@
 
 #elif TEST_STD_VER == 20
 
-# if defined(__cpp_concepts) && __cpp_concepts >= 201811L
+# ifndef _LIBCPP_HAS_NO_CONCEPTS
 #   ifndef __cpp_lib_math_constants
 #     error "__cpp_lib_math_constants should be defined in c++20"
 #   endif
 #   endif
 # else
 #   ifdef __cpp_lib_math_constants
-#     error "__cpp_lib_math_constants should not be defined when defined(__cpp_concepts) && __cpp_concepts >= 201811L is not defined!"
+#     error "__cpp_lib_math_constants should not be defined when defined(__cpp_concepts) && __cpp_concepts >= 201907L is not defined!"
 #   endif
-# endif
+# endif // _LIBCPP_HAS_NO_CONCEPTS
 
 #elif TEST_STD_VER > 20
 
-# if defined(__cpp_concepts) && __cpp_concepts >= 201811L
+# ifndef _LIBCPP_HAS_NO_CONCEPTS
 #   ifndef __cpp_lib_math_constants
 #     error "__cpp_lib_math_constants should be defined in c++2b"
 #   endif
@@ -66,9 +66,9 @@
 #   endif
 # else
 #   ifdef __cpp_lib_math_constants
-#     error "__cpp_lib_math_constants should not be defined when defined(__cpp_concepts) && __cpp_concepts >= 201811L is not defined!"
+#     error "__cpp_lib_math_constants should not be defined when defined(__cpp_concepts) && __cpp_concepts >= 201907L is not defined!"
 #   endif
-# endif
+# endif // _LIBCPP_HAS_NO_CONCEPTS
 
 #endif // TEST_STD_VER > 20
 
index e99b800..d7fabec 100644 (file)
 #   error "__cpp_lib_map_try_emplace should have the value 201411L in c++20"
 # endif
 
-# if defined(__cpp_concepts) && __cpp_concepts >= 201811L
+# ifndef _LIBCPP_HAS_NO_CONCEPTS
 #   ifndef __cpp_lib_math_constants
 #     error "__cpp_lib_math_constants should be defined in c++20"
 #   endif
 #   endif
 # else
 #   ifdef __cpp_lib_math_constants
-#     error "__cpp_lib_math_constants should not be defined when defined(__cpp_concepts) && __cpp_concepts >= 201811L is not defined!"
+#     error "__cpp_lib_math_constants should not be defined when defined(__cpp_concepts) && __cpp_concepts >= 201907L is not defined!"
 #   endif
-# endif
+# endif // _LIBCPP_HAS_NO_CONCEPTS
 
 # if !defined(_LIBCPP_VERSION)
 #   ifndef __cpp_lib_math_special_functions
 #   error "__cpp_lib_map_try_emplace should have the value 201411L in c++2b"
 # endif
 
-# if defined(__cpp_concepts) && __cpp_concepts >= 201811L
+# if !_LIBCPP_HAS_NO_CONCEPTS
 #   ifndef __cpp_lib_math_constants
 #     error "__cpp_lib_math_constants should be defined in c++2b"
 #   endif
 #   endif
 # else
 #   ifdef __cpp_lib_math_constants
-#     error "__cpp_lib_math_constants should not be defined when defined(__cpp_concepts) && __cpp_concepts >= 201811L is not defined!"
+#     error "__cpp_lib_math_constants should not be defined when defined(__cpp_concepts) && __cpp_concepts >= 201907L is not defined!"
 #   endif
-# endif
+# endif // !_LIBCPP_HAS_NO_CONCEPTS
 
 # if !defined(_LIBCPP_VERSION)
 #   ifndef __cpp_lib_math_special_functions
index a7360c3..1544baf 100755 (executable)
@@ -422,8 +422,8 @@ feature_test_macros = [ add_version_header(x) for x in [
     "name": "__cpp_lib_math_constants",
     "values": { "c++20": 201907 },
     "headers": ["numbers"],
-    "depends": "defined(__cpp_concepts) && __cpp_concepts >= 201811L",
-    "internal_depends": "defined(__cpp_concepts) && __cpp_concepts >= 201811L",
+    "depends": "defined(__cpp_concepts) && __cpp_concepts >= 201907L",
+    "internal_depends": "defined(__cpp_concepts) && __cpp_concepts >= 201907L",
   }, {
     "name": "__cpp_lib_math_special_functions",
     "values": { "c++17": 201603 },
index 3353f00..e54cece 100644 (file)
@@ -36,7 +36,7 @@ DEFAULT_FEATURES = [
   Feature(name='libcpp-no-if-constexpr',        when=lambda cfg: '__cpp_if_constexpr' not in featureTestMacros(cfg)),
   Feature(name='libcpp-no-structured-bindings', when=lambda cfg: '__cpp_structured_bindings' not in featureTestMacros(cfg)),
   Feature(name='libcpp-no-deduction-guides',    when=lambda cfg: featureTestMacros(cfg).get('__cpp_deduction_guides', 0) < 201611),
-  Feature(name='libcpp-no-concepts',            when=lambda cfg: featureTestMacros(cfg).get('__cpp_concepts', 0) < 201811),
+  Feature(name='libcpp-no-concepts',            when=lambda cfg: featureTestMacros(cfg).get('__cpp_concepts', 0) < 201907),
   Feature(name='has-fobjc-arc',                 when=lambda cfg: hasCompileFlag(cfg, '-xobjective-c++ -fobjc-arc') and
                                                                  sys.platform.lower().strip() == 'darwin'), # TODO: this doesn't handle cross-compiling to Apple platforms.
   Feature(name='objective-c++',                 when=lambda cfg: hasCompileFlag(cfg, '-xobjective-c++ -fobjc-arc')),