__fp16 is ambiguous error in C++

ALO rjiejie@linux.alibaba.com
Fri Jun 25 02:25:55 GMT 2021


#include <math.h>

__fp16 foo (__fp16 a, __fp16 b)
{
return a + std::exp(b);
}

compiler options:
=================

riscv64-unknown-linux-gnu-g++ foo.c -march=rv64gc_zfh -mabi=lp64

error:
======

foo.c: In function '__fp16 foo(__fp16, __fp16)':
foo.c:6:23: error: call of overloaded 'exp(__fp16&)' is ambiguous
6 | return a + std::exp(b);
| ^
In file included from $INSTALL/sysroot/usr/include/features.h:465,
from $INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/riscv64-unknown-linux-gnu/bits/os_defines.h:39,
from $INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/riscv64-unknown-linux-gnu/bits/c++config.h:518,
from $INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/cmath:41,
from $INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/math.h:36,
from foo.c:2:
$INSTALL/sysroot/usr/include/bits/mathcalls.h:95:1: note: candidate: 'double exp(double)'
95 | __MATHCALL_VEC (exp,, (Mdouble __x));
| ^~~~~~~~~~~~~~
In file included from $INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/math.h:36,
from foo.c:2:
$INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/cmath:222:3: note: candidate: 'constexpr float std::exp(float)'
222 | exp(float __x)
| ^~~
$INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/cmath:226:3: note: candidate: 'constexpr long double std::exp(long double)'
226 | exp(long double __x)
| ^~~

I think there is no prototype of __fp16 in libmath of glibc,
I could cast '__fp16' to 'float' or 'double' to fix this issue with modifying code, it's not invisible for developers :(

Is there any other method to fix this ?

Maybe there is some c++ compiler's option for this ?

— Jojo


More information about the Gcc mailing list