Newlib's complex.h is incompatible with GCC 9's tgmath.h

Ruslan Kabatsayev via Newlib <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CAHEcG97_Bo5iL7tJSKO_dM+sQN-sNVTKqpqfhQvvAF=dq0g4Aw@mail.gmail.com>
Hi all,

I was trying to compile a C file that uses the cos macro from
tgmath.h, and on Ubuntu 18.04 (gcc 6.3.1 arm-none-eabi, newlib 2.4.0)
it worked fine. But when trying to do the same compilation on Ubuntu
20.04 (gcc 9.2.1 arm-none-eabi, newlib 3.3.0), I get some errors.

I've reduced the test file to the following code:
```
#include <tgmath.h>

void test()
{
    double x=cos(4.5);
}
```
The errors from GCC are as follows:
```
In file included from test.c:1:
test.c: In function 'test':
test.c:5:14: error: 'ccosl' undeclared (first use in this function);
did you mean 'ccosh'?
    5 |     double x=cos(4.5);
      |              ^~~
test.c:5:14: note: each undeclared identifier is reported only once
for each function it appears in
test.c:5:14: error: argument 6 of '__builtin_tgmath' is not a function pointer
```

The difference between GCC 6 and GCC 9 is in the way the macros in
tgmath.h are defined. In GCC 6 they are in terms of
__builtin_choose_expr / __builtin_classify_type /
__builtin_types_compatible_p, which don't evaluate inactive
alternatives. And in GCC 9 they are defined via __builtin_tgmath,
which requires all alternatives to be valid function pointers.

So the current complex.h header from Newlib appears incompatible with
GCC 9's tgmath.h. A fix, I suppose, is at least to declare the missing
functions like ccosl. The best way would of course be to provide them
in full.

Regards,
Ruslan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.