Skip to content

Commit ce33a48

Browse files
authored
[libc] Keep headers compatible with -std=c89 mode (#121981)
C89 doesn't have the `restrict` keyword. When in `-std=c89` mode, GNU-compatible compilers require the `__restrict` spelling.
1 parent 6869425 commit ce33a48

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

libc/include/__llvm-libc-common.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@
5050
#define __END_C_DECLS
5151

5252
#undef __restrict
53-
#define __restrict restrict // C99 and above support the restrict keyword.
53+
#if __STDC_VERSION__ >= 199901L
54+
// C99 and above support the restrict keyword.
55+
#define __restrict restrict
56+
#elif !defined(__GNUC__)
57+
// GNU-compatible compilers accept the __ spelling in all modes.
58+
// Otherwise, omit the qualifier for pure C89 compatibility.
59+
#define __restrict
60+
#endif
5461

5562
#undef _Noreturn
5663
#if __STDC_VERSION__ >= 201112L

0 commit comments

Comments
 (0)