[libc-commits] [libc] [libc] Define away __restrict in C++ without GNU extensions (PR #114655)

Roland McGrath via libc-commits libc-commits at lists.llvm.org
Sat Nov 2 02:33:31 PDT 2024


https://github.com/frobtech created https://github.com/llvm/llvm-project/pull/114655

The C99 restrict keyword is spelled __restrict in the libc
headers so it can be parsed by C++ compilers with GNU extensions
that recognize it.  When GNU extensions are not available in C++


>From 9655e14433906b36536678867e4e475cbd3edbff Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Sat, 2 Nov 2024 02:30:49 -0700
Subject: [PATCH] [libc] Define away __restrict in C++ without GNU extensions

The C99 restrict keyword is spelled __restrict in the libc
headers so it can be parsed by C++ compilers with GNU extensions
that recognize it.  When GNU extensions are not available in C++
---
 libc/include/__llvm-libc-common.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index 3af0b08e9e8668..e0e29bbbd5f87c 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -17,6 +17,12 @@
 #undef __END_C_DECLS
 #define __END_C_DECLS }
 
+// Standard C++ doesn't have C99 restrict but GNU C++ has it with __ spelling.
+#undef __restrict
+#ifndef __GNUC__
+#define __restrict
+#endif
+
 #undef _Noreturn
 #define _Noreturn [[noreturn]]
 



More information about the libc-commits mailing list