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.
g++ main.cpp
? – Resectstd::sinf
,std::cosf
etc were added in C++11. Are you compiling with C++11 enabled? – Cypselag++ (Debian 8.3.0-6) 8.3.0
. – Resectcosf
works in 8.3/9.1 per quick test on godbolt with--std=c++17
;std::cosf
works in neither. (Just a quick observation). – Martyrycosh
and works btw. – Polybiusstd::cos()
forfloat
... you don't needstd::cosf()
. – Fromastd::
. The compiler still finds the rightcosf
by Argument-dependent lookup The upshot being, that it also works when you replace the float with a custom type (with a customcosf
). See godbolt.org/z/cWlDgC for an example. – Gather