https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109818
Bug ID: 109818
Summary: std::trunc() requires a <cmath> hack after building
DJGPP
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: janezz55 at gmail dot com
Target Milestone: ---
After building gcc/DJGPP, the installation requires the following hack:
sed -i '/{ return __builtin_tanh(__x); }/a\
\
using ::trunc;\
\
#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO_FP\
constexpr float\
trunc(float __x)\
{ return __builtin_truncf(__x); }\
\
constexpr long double\
trunc(long double __x)\
{ return __builtin_truncl(__x); }\
#endif\
\
template<typename _Tp>\
constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, \
double>::__type\
trunc(_Tp __x)\
{ return __builtin_trunc(__x); }'
$pkgdir/usr/$_target/include/c++/$pkgver/cmath
The hack can be observed in action if you install/checkout:
https://aur.archlinux.org/packages/dosbox-gcc
If we don't apply the hack, gcc will complain about std::trunc() being
unavailable (compile error), if we try to compile an application requiring
std::trunc(), but not if it requires plain C trunc(). At least part of the
blame probably lies with DJGPP, not with libstdc++, but libstdc++ manages to
hack many other math.h functions (i.e. it seems to contain a template for the
hack, that it applies to many different math.h functions, just not to trunc()).
Perhaps a simple fix of adding trunc() to a list of functions, that need to be
hacked, is possible. Other math.h functions, not just trunc(), may also need to
be hacked into <cmath>.
Like most DJGPP-related bugs, this one is very old.