From a449e5971fc3aceff40c23fce22c42f79e7d4a0b Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Mon, 24 Aug 2020 19:27:02 +0200
Subject: [PATCH] Remove __LONG_LONG_SUPPORTED usage in our headers.

---
 .../config/os/bsd/dragonfly/os_defines.h       |  2 +-
 .../config/os/bsd/dragonfly/os_defines.h       |  2 +-
 include/stdlib.h                               | 18 +-----------------
 include/wchar.h                                |  4 ----
 share/mk/sys.mk                                |  2 +-
 sys/cpu/x86_64/include/limits.h                |  8 ++++++--
 6 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/contrib/gcc-4.7/libstdc++-v3/config/os/bsd/dragonfly/os_defines.h b/contrib/gcc-4.7/libstdc++-v3/config/os/bsd/dragonfly/os_defines.h
index 8937490038..e17706688a 100644
--- a/contrib/gcc-4.7/libstdc++-v3/config/os/bsd/dragonfly/os_defines.h
+++ b/contrib/gcc-4.7/libstdc++-v3/config/os/bsd/dragonfly/os_defines.h
@@ -33,7 +33,7 @@
 #define _GLIBCXX_USE_C99_CHECK 1
 #define _GLIBCXX_USE_C99_DYNAMIC (!(__ISO_C_VISIBLE >= 1999))
 #define _GLIBCXX_USE_C99_LONG_LONG_CHECK 1
-#define _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC (_GLIBCXX_USE_C99_DYNAMIC || !defined __LONG_LONG_SUPPORTED)
+#define _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC _GLIBCXX_USE_C99_DYNAMIC
 #define _GLIBCXX_USE_C99_FLOAT_TRANSCENDENTALS_CHECK 1
 #define _GLIBCXX_USE_C99_FLOAT_TRANSCENDENTALS_DYNAMIC defined _XOPEN_SOURCE
 */
diff --git a/contrib/gcc-8.0/libstdc++-v3/config/os/bsd/dragonfly/os_defines.h b/contrib/gcc-8.0/libstdc++-v3/config/os/bsd/dragonfly/os_defines.h
index dbb90b649e..99bae3c3f9 100644
--- a/contrib/gcc-8.0/libstdc++-v3/config/os/bsd/dragonfly/os_defines.h
+++ b/contrib/gcc-8.0/libstdc++-v3/config/os/bsd/dragonfly/os_defines.h
@@ -36,6 +36,6 @@
 #define _GLIBCXX_USE_C99_CHECK 1
 #define _GLIBCXX_USE_C99_DYNAMIC (!(__ISO_C_VISIBLE >= 1999))
 #define _GLIBCXX_USE_C99_LONG_LONG_CHECK 1
-#define _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC (_GLIBCXX_USE_C99_DYNAMIC || !defined __LONG_LONG_SUPPORTED)
+#define _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC _GLIBCXX_USE_C99_DYNAMIC
 
 #endif
diff --git a/include/stdlib.h b/include/stdlib.h
index eb572aa433..45e53aae2b 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -126,39 +126,23 @@ int	 wctomb(char *, wchar_t);
 size_t	 wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
 
 /*
- * Functions added in C99 which we make conditionally available in the
- * BSD^C89 namespace if the compiler supports `long long'.
- * The #if test is more complicated than it ought to be because
- * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
- * is not supported in the compilation environment (which therefore means
- * that it can't really be ISO C99).
- *
- * (The only other extension made by C99 in this header is _Exit().)
+ * C99 functions.
  */
 #if __ISO_C_VISIBLE >= 1999 || defined(__cplusplus)
-#ifdef __LONG_LONG_SUPPORTED
-/* LONGLONG */
 typedef struct {
 	long long quot;
 	long long rem;
 } lldiv_t;
 
-/* LONGLONG */
 long long
 	 atoll(const char *);
-/* LONGLONG */
 long long
 	 llabs(long long) __pure2;
-/* LONGLONG */
 lldiv_t	 lldiv(long long, long long) __pure2;
-/* LONGLONG */
 long long
 	 strtoll(const char * __restrict, char ** __restrict, int);
-/* LONGLONG */
 unsigned long long
 	 strtoull(const char * __restrict, char ** __restrict, int);
-#endif /* __LONG_LONG_SUPPORTED */
-
 void	 _Exit(int) __dead2;
 #endif /* __ISO_C_VISIBLE >= 1999 */
 
diff --git a/include/wchar.h b/include/wchar.h
index 81b7d3cd9a..9749b318f0 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -228,14 +228,10 @@ int	vwscanf(const wchar_t * __restrict, __va_list);
 float	wcstof(const wchar_t * __restrict, wchar_t ** __restrict);
 long double
 	wcstold(const wchar_t * __restrict, wchar_t ** __restrict);
-#ifdef __LONG_LONG_SUPPORTED
-/* LONGLONG */
 long long
 	wcstoll(const wchar_t * __restrict, wchar_t ** __restrict, int);
-/* LONGLONG */
 unsigned long long
 	 wcstoull(const wchar_t * __restrict, wchar_t ** __restrict, int);
-#endif
 #endif	/* __ISO_C_VISIBLE >= 1999 */
 
 #if __XSI_VISIBLE
diff --git a/share/mk/sys.mk b/share/mk/sys.mk
index 2130a06244..ac3d4d730a 100644
--- a/share/mk/sys.mk
+++ b/share/mk/sys.mk
@@ -61,7 +61,7 @@ CXX		?=	c++
 CXX_LINK	?=	${CXX}
 NXCXX		?=	${NXENV} ${CXX}
 NXCXX_LINK	?=	${NXENV} ${CXX_LINK}
-CXXFLAGS	?=	${CXXINCLUDES} ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition:N-Wsystem-headers}
+CXXFLAGS	?=	${CXXINCLUDES} ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
 .if !defined(SYSBUILD) && defined(.MAKE.BUILT.BY) && ${.MAKE.BUILT.BY:Mgcc47}
 CXXFLAGS	+=	-D_GLIBCXX_USE_CXX11_ABI=0
 .endif
diff --git a/sys/cpu/x86_64/include/limits.h b/sys/cpu/x86_64/include/limits.h
index 957855ddf0..7d636bca1f 100644
--- a/sys/cpu/x86_64/include/limits.h
+++ b/sys/cpu/x86_64/include/limits.h
@@ -74,7 +74,9 @@
 #define	LONG_MAX	0x7fffffffffffffffL	/* max for a long */
 #define	LONG_MIN	(-0x7fffffffffffffffL - 1) /* min for a long */
 
-#ifdef __LONG_LONG_SUPPORTED
+#if (__GNUC_PREREQ__(2, 0) && !defined(__STRICT_ANSI__)) || \
+    (defined(__cplusplus) && __cplusplus >= 201103L) || \
+    __STDC_VERSION__ >= 199901
 #define	ULLONG_MAX	0xffffffffffffffffULL	/* max value for an unsigned long long */
 #define	LLONG_MAX	0x7fffffffffffffffLL	/* max value for a long long */
 #define	LLONG_MIN	(-0x7fffffffffffffffLL - 1)  /* min for a long long */
@@ -84,7 +86,9 @@
 #define	LONG_MAX	0x7fffffffUL		/* max for a long */
 #define	LONG_MIN	(-0x7fffffffL - 1)	/* min for a long */
 
-#ifdef __LONG_LONG_SUPPORTED
+#if (__GNUC_PREREQ__(2, 0) && !defined(__STRICT_ANSI__)) || \
+    (defined(__cplusplus) && __cplusplus >= 201103L) || \
+    __STDC_VERSION__ >= 199901
 #define	ULLONG_MAX	0xffffffffULL		/* max value for an unsigned long long */
 #define	LLONG_MAX	0x7fffffffLL		/* max value for a long long */
 #define	LLONG_MIN	(-0x7fffffffLL - 1)	/* min for a long long */
-- 
2.27.0

