__restrict defined away for C++
Jim Wilson <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CAFyWVab4RES_jp5rxcKMO4BRXmFWtxaSjuRSS916=ApxSLifEQ@mail.gmail.com> |
This problem was originally reported on the RISC-V sw-dev mailing list. https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/b55LI9OSFwo/m/d8-_NGmlAQAJ I see that newlib/libc/include/sys/cdefs.h has /* * GCC 2.95 provides `__restrict' as an extension to C90 to support the * C99-specific `restrict' type qualifier. We happen to use `__restrict' as * a way to define the `restrict' type qualifier without disturbing older * software that is unaware of C99 keywords. */ #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 #define __restrict #else #define __restrict restrict #endif #endif The flaw here is that C++ compilers don't define __STDC_VERSION so this always causes __restrict to be defined away, even if the C++ compiler supports it. This prevents use of the GNU extension __restrict in C++ code. The workaround is to use __restrict__ in user code which GNU C++ also supports, and which newlib doesn't define away. I don't have a patch. I'm hoping someone else writes one. One possible solution is to use a different keyword inside newlib, e.g. __newlib_retrict. This way we don't conflict with the compiler __restrict feature. Though this means newlib functions will be declared without __restrict. Another solution would be to check for C++ compilers with __restrict support and support them. Or maybe both of these are appropriate. We may not need the gcc-2.95 support anymore. Jim