`cosf`, `sinf`, etc. are not in `std` [duplicate]

我只是一个虾纸丫 提交于 2019-12-03 23:43:25

That version of the library (libstdc++8) is not fully conforming to C++17. The copyright notice says it was last updated in 2016. As of June 2019, the latest upstream release is bugged. It does have a #if __cplusplus > 201402L section, but it doesn’t declare the identifiers required by C++17. There is an open bug report.

Looking at /usr/include/c++/8/cmath on Ubuntu, it includes <math.h>, undefines a series of macros for its functions (required by the C standard library) to access their names, imports cos, acos, etc. into the std:: namespace, and then declares the overloaded float and long double overloads as inline.

It never declares cosf within the std:: namespace, even though C++17 says it shall. The C++11 standard says, “Names that are defined as functions in C shall be defined as functions in the C++ standard library,” and “Each name from the Standard C library declared with external linkage is reserved to the implementation for use as a name with extern "C" linkage, both in namespace std and in the global namespace.” However, it does not explicitly state that std::expf et al. must be supported until P0175r1 in June 2016. This was apparently an oversight.

The libc++ library does declare them, so compiling with clang++ -std=c++17 -stdlib=libc++ should work.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!