public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* __fp16 is ambiguous error in C++
       [not found] <9855c87e-23db-48f0-ab98-bf2437022148@Spark>
@ 2021-06-25  2:25 ` ALO
  2021-06-25 21:48   ` Jim Wilson
  2021-06-25 21:57   ` Jonathan Wakely
  0 siblings, 2 replies; 3+ messages in thread
From: ALO @ 2021-06-25  2:25 UTC (permalink / raw)
  To: gcc

#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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: __fp16 is ambiguous error in C++
  2021-06-25  2:25 ` __fp16 is ambiguous error in C++ ALO
@ 2021-06-25 21:48   ` Jim Wilson
  2021-06-25 21:57   ` Jonathan Wakely
  1 sibling, 0 replies; 3+ messages in thread
From: Jim Wilson @ 2021-06-25 21:48 UTC (permalink / raw)
  To: ALO; +Cc: GCC Development

On Thu, Jun 24, 2021 at 7:26 PM ALO via Gcc <gcc@gcc.gnu.org> wrote:

> 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);
> | ^
>

No, there isn't a solution for this.  You might want to try an ARM port
clang/gcc to see what they do, but it probably isn't much better than the
RISC-V port.  Looks like the same gcc result to me with a quick check.  And
note that only the non-upstream V extension branch for RISC-V has the
__fp16 support because the vector extension depends on it.  It is hard to
argue for changes when the official RISC-V GCC port has no __fp16 support.

Kito started a related thread in March, and there was tentative agreement
to add _Float16 support to the GCC C++ front end.
https://gcc.gnu.org/pipermail/gcc/2021-March/234971.html
That may or may not help you.

I think it will be difficult to do anything useful here until the C and C++
standards figure out how they want half-float support to work.  If we do
something before then, it will probably end up incompatible with the
official solution and we will end up stuck with a mess.

Jim

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: __fp16 is ambiguous error in C++
  2021-06-25  2:25 ` __fp16 is ambiguous error in C++ ALO
  2021-06-25 21:48   ` Jim Wilson
@ 2021-06-25 21:57   ` Jonathan Wakely
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2021-06-25 21:57 UTC (permalink / raw)
  To: rjiejie; +Cc: gcc

> foo.c:6:23: error: call of overloaded 'exp(__fp16&)' is ambiguous

__fp16 isn't ambiguous, calling std::exp with an argument of that type
is ambiguous, because the standard library doesn't provide an overload
for that type.

It could be added (probably defined to cast to float and use the
overload for float), but we would need to do it for every function in
<math.h>. It's a simple matter of programming, but somebody needs to
do the work.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-25 21:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <9855c87e-23db-48f0-ab98-bf2437022148@Spark>
2021-06-25  2:25 ` __fp16 is ambiguous error in C++ ALO
2021-06-25 21:48   ` Jim Wilson
2021-06-25 21:57   ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).