jlebar updated this revision to Diff 77271. jlebar added a comment. Use TEST_STD_VER macro.
https://reviews.llvm.org/D25403 Files: libcxx/include/cmath libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp Index: libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Check that the overloads of std::__libcpp_{isnan,isinf,isfinite} that take +// floating-point values are evaluatable from constexpr contexts. +// +// These functions need to be constexpr in order to be called from CUDA, see +// https://reviews.llvm.org/D25403. They don't actually need to be +// constexpr-evaluatable, but that's what we check here, since we can't check +// true constexpr-ness. + +#include <cmath> + +#include "test_macros.h" + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +#if TEST_STD_VER >= 11 +constexpr bool a = std::__libcpp_isnan(0.); +constexpr bool b = std::__libcpp_isinf(0.0); +constexpr bool c = std::__libcpp_isfinite(0.0); +#endif + +int main() +{ + return 0; +} Index: libcxx/include/cmath =================================================================== --- libcxx/include/cmath +++ libcxx/include/cmath @@ -560,7 +560,7 @@ template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isnan) @@ -572,15 +572,15 @@ template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<!is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT { return isnan(__lcpp_x); } template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isinf) @@ -592,15 +592,15 @@ template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<!is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT { return isinf(__lcpp_x); } template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isfinite) @@ -612,7 +612,7 @@ template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<!is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT { return isfinite(__lcpp_x);
Index: libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Check that the overloads of std::__libcpp_{isnan,isinf,isfinite} that take +// floating-point values are evaluatable from constexpr contexts. +// +// These functions need to be constexpr in order to be called from CUDA, see +// https://reviews.llvm.org/D25403. They don't actually need to be +// constexpr-evaluatable, but that's what we check here, since we can't check +// true constexpr-ness. + +#include <cmath> + +#include "test_macros.h" + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +#if TEST_STD_VER >= 11 +constexpr bool a = std::__libcpp_isnan(0.); +constexpr bool b = std::__libcpp_isinf(0.0); +constexpr bool c = std::__libcpp_isfinite(0.0); +#endif + +int main() +{ + return 0; +} Index: libcxx/include/cmath =================================================================== --- libcxx/include/cmath +++ libcxx/include/cmath @@ -560,7 +560,7 @@ template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isnan) @@ -572,15 +572,15 @@ template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<!is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT { return isnan(__lcpp_x); } template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isinf) @@ -592,15 +592,15 @@ template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<!is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT { return isinf(__lcpp_x); } template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isfinite) @@ -612,7 +612,7 @@ template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<!is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT { return isfinite(__lcpp_x);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits