newlib icon indicating copy to clipboard operation
newlib copied to clipboard

[devkitARM] newlib 4.4.0 update broke ``__restrict`` keyword in c++ (nds)

Open edo9300 opened this issue 1 year ago • 0 comments

As analyzed in this other conversation, in the commit https://github.com/devkitPro/newlib/commit/3c75fac130b5720068707f67b12f4372abf4ad38 (done by upstream) the logic whether to define or not __restrict keyword was changed, and now it is assumed to always be existing even in c++ mode, thus it's not redefined as an empty macro. Unfortunately the gcc shipped with dkp doesn't seem to support that keyword at all, even when compiling with gnu extensions (with -std=gnu++XX).

#include <sys/types.h>
#include <regex.h>

int main() {
    return 0;
}

Attempting to compile this sample code as cpp will error out

In file included from C:/devkitPro/examples/nds/templates/arm9/source/main.cpp:2:
C:/devkitPro/devkitARM/arm-none-eabi/include/regex.h:99:45: error: expected primary-expression before '__restrict'
   99 |                         size_t, regmatch_t [__restrict], int);
      |                                             ^~~~~~~~~~
C:/devkitPro/devkitARM/arm-none-eabi/include/regex.h:99:45: error: expected ']' before '__restrict'
   99 |                         size_t, regmatch_t [__restrict], int);
      |                                             ^~~~~~~~~~
      |                                             ]
C:/devkitPro/devkitARM/arm-none-eabi/include/regex.h:99:45: error: expected ')' before '__restrict'
   99 |                         size_t, regmatch_t [__restrict], int);
      |                                             ^~~~~~~~~~
      |                                             )
C:/devkitPro/devkitARM/arm-none-eabi/include/regex.h:98:16: note: to match this '('
   98 | int     regexec(const regex_t *__restrict, const char *__restrict,
      |                ^
C:/devkitPro/devkitARM/arm-none-eabi/include/regex.h:99:55: error: expected initializer before ']' token
   99 |                         size_t, regmatch_t [__restrict], int);

In this case the __restrict keyword is being used by the regex.h header, another component of newlib.

edo9300 avatar Feb 26 '24 17:02 edo9300