#1076160 g++: _Float16 does not work in G++ (works in GCC) on aarch64

Package:
g++
Source:
g++
Description:
GNU C++ compiler
Submitter:
Mike Green
Date:
2024-07-15 16:09:03 UTC
Severity:
normal
Tags:
#1076160#5
Date:
2024-07-11 18:13:44 UTC
From:
To:
I'm looking to use 16b IEEE floating point on ARM Linux which is supported by my target, and successfully compiles with GCC.  Alas, the same file fails to compaile with G++:

float test(_Float16 x){
return x;
}

#1076160#18
Date:
2024-07-15 16:08:21 UTC
From:
To:
Hi,

I could reproduce the problem with GCC 12 on aarch64, but not with GCC
13 and 14.

Using the following test program:

  #include <stdio.h>

  float test(_Float16 x){
    return x;
  }

  int main() {
    printf("%f\n", test(1.0));
  }

This is the error message you get on aarch64 with g++-12:

  $ g++-12 x.c
  x.c:3:12: error: '_Float16' was not declared in this scope; did you mean '_Float64'?
      3 | float test(_Float16 x){
        |            ^~~~~~~~
        |            _Float64
  x.c: In function 'int main()':
  x.c:8:22: error: 'test' cannot be used as a function
      8 |   printf("%f\n", test(1.0));
        |                  ~~~~^~~~~

The same program builds fine with g++-12 on x86_64.

Note that with GCC 13 and 14 the code compiles and works (ie: it prints
"1.000000") albeit with some warnings. This is the same behavior you get
on x86_64 as well, with GCC 13 and 14.

  $ g++-13 x.c
  x.c: In function 'int main()':
  x.c:8:23: warning: converting to '_Float16' from 'double' with greater conversion rank
      8 |   printf("%f\n", test(1.0));
        |                       ^~~
  x.c:3:21: note:   initializing argument 1 of 'float test(_Float16)'
      3 | float test(_Float16 x){
        |            ~~~~~~~~~^