mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 12:02:36 +08:00
Add fenv.h header
Summary: Some implementations of fenv.h use macros to define the functions they provide. This can cause problems when `std::fegetround()` is spelled in source. This patch adds a `fenv.h` header to libc++ for the sole purpose of turning those macros into real functions. Reviewers: rsmith, mclow.lists, ldionne Reviewed By: rsmith Subscribers: mgorny, christof, libcxx-commits Differential Revision: https://reviews.llvm.org/D57729 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@353767 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -95,6 +95,7 @@ set(files
|
|||||||
ext/__hash
|
ext/__hash
|
||||||
ext/hash_map
|
ext/hash_map
|
||||||
ext/hash_set
|
ext/hash_set
|
||||||
|
fenv.h
|
||||||
filesystem
|
filesystem
|
||||||
float.h
|
float.h
|
||||||
forward_list
|
forward_list
|
||||||
|
|||||||
204
include/fenv.h
Normal file
204
include/fenv.h
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
//===---------------------------- math.h ----------------------------------===//
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef _LIBCPP_FENV_H
|
||||||
|
#define _LIBCPP_FENV_H
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
fenv.h synopsis
|
||||||
|
|
||||||
|
This entire header is C99 / C++0X
|
||||||
|
|
||||||
|
Macros:
|
||||||
|
|
||||||
|
FE_DIVBYZERO
|
||||||
|
FE_INEXACT
|
||||||
|
FE_INVALID
|
||||||
|
FE_OVERFLOW
|
||||||
|
FE_UNDERFLOW
|
||||||
|
FE_ALL_EXCEPT
|
||||||
|
FE_DOWNWARD
|
||||||
|
FE_TONEAREST
|
||||||
|
FE_TOWARDZERO
|
||||||
|
FE_UPWARD
|
||||||
|
FE_DFL_ENV
|
||||||
|
|
||||||
|
Types:
|
||||||
|
|
||||||
|
fenv_t
|
||||||
|
fexcept_t
|
||||||
|
|
||||||
|
int feclearexcept(int excepts);
|
||||||
|
int fegetexceptflag(fexcept_t* flagp, int excepts);
|
||||||
|
int feraiseexcept(int excepts);
|
||||||
|
int fesetexceptflag(const fexcept_t* flagp, int excepts);
|
||||||
|
int fetestexcept(int excepts);
|
||||||
|
int fegetround();
|
||||||
|
int fesetround(int round);
|
||||||
|
int fegetenv(fenv_t* envp);
|
||||||
|
int feholdexcept(fenv_t* envp);
|
||||||
|
int fesetenv(const fenv_t* envp);
|
||||||
|
int feupdateenv(const fenv_t* envp);
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <__config>
|
||||||
|
#include_next <fenv.h>
|
||||||
|
|
||||||
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||||
|
#pragma GCC system_header
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
extern "C++" {
|
||||||
|
|
||||||
|
#ifdef feclearexcept
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_feclearexcept(int __excepts) {
|
||||||
|
return feclearexcept(__excepts);
|
||||||
|
}
|
||||||
|
#undef feclearexcept
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int feclearexcept(int __excepts) {
|
||||||
|
return ::__libcpp_feclearexcept(__excepts);
|
||||||
|
}
|
||||||
|
#endif // defined(feclearexcept)
|
||||||
|
|
||||||
|
#ifdef fegetexceptflag
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_fegetexceptflag(fexcept_t* __out_ptr, int __excepts) {
|
||||||
|
return fegetexceptflag(__out_ptr, __excepts);
|
||||||
|
}
|
||||||
|
#undef fegetexceptflag
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int fegetexceptflag(fexcept_t *__out_ptr, int __excepts) {
|
||||||
|
return ::__libcpp_fegetexceptflag(__out_ptr, __excepts);
|
||||||
|
}
|
||||||
|
#endif // defined(fegetexceptflag)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef feraiseexcept
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_feraiseexcept(int __excepts) {
|
||||||
|
return feraiseexcept(__excepts);
|
||||||
|
}
|
||||||
|
#undef feraiseexcept
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int feraiseexcept(int __excepts) {
|
||||||
|
return ::__libcpp_feraiseexcept(__excepts);
|
||||||
|
}
|
||||||
|
#endif // defined(feraiseexcept)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef fesetexceptflag
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_fesetexceptflag(const fexcept_t* __out_ptr, int __excepts) {
|
||||||
|
return fesetexceptflag(__out_ptr, __excepts);
|
||||||
|
}
|
||||||
|
#undef fesetexceptflag
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int fesetexceptflag(const fexcept_t *__out_ptr, int __excepts) {
|
||||||
|
return ::__libcpp_fesetexceptflag(__out_ptr, __excepts);
|
||||||
|
}
|
||||||
|
#endif // defined(fesetexceptflag)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef fetestexcept
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_fetestexcept(int __excepts) {
|
||||||
|
return fetestexcept(__excepts);
|
||||||
|
}
|
||||||
|
#undef fetestexcept
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int fetestexcept(int __excepts) {
|
||||||
|
return ::__libcpp_fetestexcept(__excepts);
|
||||||
|
}
|
||||||
|
#endif // defined(fetestexcept)
|
||||||
|
|
||||||
|
#ifdef fegetround
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_fegetround() {
|
||||||
|
return fegetround();
|
||||||
|
}
|
||||||
|
#undef fegetround
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int fegetround() {
|
||||||
|
return ::__libcpp_fegetround();
|
||||||
|
}
|
||||||
|
#endif // defined(fegetround)
|
||||||
|
|
||||||
|
#ifdef fesetround
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_fesetround(int __round) {
|
||||||
|
return fesetround(__round);
|
||||||
|
}
|
||||||
|
#undef fesetround
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int fesetround(int __round) {
|
||||||
|
return ::__libcpp_fesetround(__round);
|
||||||
|
}
|
||||||
|
#endif // defined(fesetround)
|
||||||
|
|
||||||
|
#ifdef fegetenv
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_fegetenv(fenv_t* __envp) {
|
||||||
|
return fegetenv(__envp);
|
||||||
|
}
|
||||||
|
#undef fegetenv
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int fegetenv(fenv_t* __envp) {
|
||||||
|
return ::__libcpp_fegetenv(__envp);
|
||||||
|
}
|
||||||
|
#endif // defined(fegetenv)
|
||||||
|
|
||||||
|
#ifdef feholdexcept
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_feholdexcept(fenv_t* __envp) {
|
||||||
|
return feholdexcept(__envp);
|
||||||
|
}
|
||||||
|
#undef feholdexcept
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int feholdexcept(fenv_t* __envp) {
|
||||||
|
return ::__libcpp_feholdexcept(__envp);
|
||||||
|
}
|
||||||
|
#endif // defined(feholdexcept)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef fesetenv
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_fesetenv(const fenv_t* __envp) {
|
||||||
|
return fesetenv(__envp);
|
||||||
|
}
|
||||||
|
#undef fesetenv
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int fesetenv(const fenv_t* __envp) {
|
||||||
|
return ::__libcpp_fesetenv(__envp);
|
||||||
|
}
|
||||||
|
#endif // defined(fesetenv)
|
||||||
|
|
||||||
|
#ifdef feupdateenv
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int __libcpp_feupdateenv(const fenv_t* __envp) {
|
||||||
|
return feupdateenv(__envp);
|
||||||
|
}
|
||||||
|
#undef feupdateenv
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
inline int feupdateenv(const fenv_t* __envp) {
|
||||||
|
return ::__libcpp_feupdateenv(__envp);
|
||||||
|
}
|
||||||
|
#endif // defined(feupdateenv)
|
||||||
|
|
||||||
|
} // extern "C++"
|
||||||
|
|
||||||
|
#endif // defined(__cplusplus)
|
||||||
|
|
||||||
|
#endif // _LIBCPP_FENV_H
|
||||||
@@ -24,7 +24,10 @@ module std [system] {
|
|||||||
header "errno.h"
|
header "errno.h"
|
||||||
export *
|
export *
|
||||||
}
|
}
|
||||||
// <fenv.h> provided by C library.
|
module fenv_h {
|
||||||
|
header "fenv.h"
|
||||||
|
export *
|
||||||
|
}
|
||||||
// <float.h> provided by compiler or C library.
|
// <float.h> provided by compiler or C library.
|
||||||
module inttypes_h {
|
module inttypes_h {
|
||||||
header "inttypes.h"
|
header "inttypes.h"
|
||||||
|
|||||||
19
test/libcxx/depr/depr.c.headers/fenv.pass.cpp
Normal file
19
test/libcxx/depr/depr.c.headers/fenv.pass.cpp
Normal file
@@ -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
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <fenv.h>
|
||||||
|
|
||||||
|
#include <fenv.h>
|
||||||
|
|
||||||
|
#ifndef _LIBCPP_VERSION
|
||||||
|
#error _LIBCPP_VERSION not defined
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -63,6 +63,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <fenv.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <forward_list>
|
#include <forward_list>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <complex.h>
|
#include <complex.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fenv.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|||||||
@@ -61,17 +61,17 @@ int main(int, char**)
|
|||||||
{
|
{
|
||||||
fenv_t fenv = {};
|
fenv_t fenv = {};
|
||||||
fexcept_t fex = 0;
|
fexcept_t fex = 0;
|
||||||
static_assert((std::is_same<decltype(feclearexcept(0)), int>::value), "");
|
static_assert((std::is_same<decltype(::feclearexcept(0)), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(fegetexceptflag(&fex, 0)), int>::value), "");
|
static_assert((std::is_same<decltype(::fegetexceptflag(&fex, 0)), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(feraiseexcept(0)), int>::value), "");
|
static_assert((std::is_same<decltype(::feraiseexcept(0)), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(fesetexceptflag(&fex, 0)), int>::value), "");
|
static_assert((std::is_same<decltype(::fesetexceptflag(&fex, 0)), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(fetestexcept(0)), int>::value), "");
|
static_assert((std::is_same<decltype(::fetestexcept(0)), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(fegetround()), int>::value), "");
|
static_assert((std::is_same<decltype(::fegetround()), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(fesetround(0)), int>::value), "");
|
static_assert((std::is_same<decltype(::fesetround(0)), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(fegetenv(&fenv)), int>::value), "");
|
static_assert((std::is_same<decltype(::fegetenv(&fenv)), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(feholdexcept(&fenv)), int>::value), "");
|
static_assert((std::is_same<decltype(::feholdexcept(&fenv)), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(fesetenv(&fenv)), int>::value), "");
|
static_assert((std::is_same<decltype(::fesetenv(&fenv)), int>::value), "");
|
||||||
static_assert((std::is_same<decltype(feupdateenv(&fenv)), int>::value), "");
|
static_assert((std::is_same<decltype(::feupdateenv(&fenv)), int>::value), "");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user