kirkwood: add D-Link DNS-320L support
[openwrt/openwrt.git] / toolchain / gcc / patches-12.x / 020-Include-safe-ctype.h-after-C-standard-headers-to-avo.patch
1 From 9970b576b7e4ae337af1268395ff221348c4b34a Mon Sep 17 00:00:00 2001
2 From: Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
3 Date: Thu, 7 Mar 2024 14:36:03 +0100
4 Subject: [PATCH] Include safe-ctype.h after C++ standard headers, to avoid
5 over-poisoning
6
7 When building gcc's C++ sources against recent libc++, the poisoning of
8 the ctype macros due to including safe-ctype.h before including C++
9 standard headers such as <list>, <map>, etc, causes many compilation
10 errors, similar to:
11
12 In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23:
13 In file included from /home/dim/src/gcc/master/gcc/system.h:233:
14 In file included from /usr/include/c++/v1/vector:321:
15 In file included from
16 /usr/include/c++/v1/__format/formatter_bool.h:20:
17 In file included from
18 /usr/include/c++/v1/__format/formatter_integral.h:32:
19 In file included from /usr/include/c++/v1/locale:202:
20 /usr/include/c++/v1/__locale:546:5: error: '__abi_tag__' attribute
21 only applies to structs, variables, functions, and namespaces
22 546 | _LIBCPP_INLINE_VISIBILITY
23 | ^
24 /usr/include/c++/v1/__config:813:37: note: expanded from macro
25 '_LIBCPP_INLINE_VISIBILITY'
26 813 | # define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
27 | ^
28 /usr/include/c++/v1/__config:792:26: note: expanded from macro
29 '_LIBCPP_HIDE_FROM_ABI'
30 792 |
31 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(
32 _LIBCPP_VERSIONED_IDENTIFIER))))
33 | ^
34 In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23:
35 In file included from /home/dim/src/gcc/master/gcc/system.h:233:
36 In file included from /usr/include/c++/v1/vector:321:
37 In file included from
38 /usr/include/c++/v1/__format/formatter_bool.h:20:
39 In file included from
40 /usr/include/c++/v1/__format/formatter_integral.h:32:
41 In file included from /usr/include/c++/v1/locale:202:
42 /usr/include/c++/v1/__locale:547:37: error: expected ';' at end of
43 declaration list
44 547 | char_type toupper(char_type __c) const
45 | ^
46 /usr/include/c++/v1/__locale:553:48: error: too many arguments
47 provided to function-like macro invocation
48 553 | const char_type* toupper(char_type* __low, const
49 char_type* __high) const
50 | ^
51 /home/dim/src/gcc/master/gcc/../include/safe-ctype.h:146:9: note:
52 macro 'toupper' defined here
53 146 | #define toupper(c) do_not_use_toupper_with_safe_ctype
54 | ^
55
56 This is because libc++ uses different transitive includes than
57 libstdc++, and some of those transitive includes pull in various ctype
58 declarations (typically via <locale>).
59
60 There was already a special case for including <string> before
61 safe-ctype.h, so move the rest of the C++ standard header includes to
62 the same location, to fix the problem.
63
64 gcc/ChangeLog:
65
66 * system.h: Include safe-ctype.h after C++ standard headers.
67
68 Signed-off-by: Dimitry Andric <dimitry@andric.com>
69 ---
70 gcc/system.h | 39 ++++++++++++++++++---------------------
71 1 file changed, 18 insertions(+), 21 deletions(-)
72
73 diff --git a/gcc/system.h b/gcc/system.h
74 index b0edab02885..ab29fc19776 100644
75 --- a/gcc/system.h
76 +++ b/gcc/system.h
77 @@ -194,27 +194,8 @@ extern int fprintf_unlocked (FILE *, const char *, ...);
78 #undef fread_unlocked
79 #undef fwrite_unlocked
80
81 -/* Include <string> before "safe-ctype.h" to avoid GCC poisoning
82 - the ctype macros through safe-ctype.h */
83 -
84 -#ifdef __cplusplus
85 -#ifdef INCLUDE_STRING
86 -# include <string>
87 -#endif
88 -#endif
89 -
90 -/* There are an extraordinary number of issues with <ctype.h>.
91 - The last straw is that it varies with the locale. Use libiberty's
92 - replacement instead. */
93 -#include "safe-ctype.h"
94 -
95 -#include <sys/types.h>
96 -
97 -#include <errno.h>
98 -
99 -#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
100 -extern int errno;
101 -#endif
102 +/* Include C++ standard headers before "safe-ctype.h" to avoid GCC
103 + poisoning the ctype macros through safe-ctype.h */
104
105 #ifdef __cplusplus
106 #if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY)
107 @@ -229,6 +210,9 @@ extern int errno;
108 #ifdef INCLUDE_SET
109 # include <set>
110 #endif
111 +#ifdef INCLUDE_STRING
112 +# include <string>
113 +#endif
114 #ifdef INCLUDE_VECTOR
115 # include <vector>
116 #endif
117 @@ -245,6 +229,19 @@ extern int errno;
118 # include <type_traits>
119 #endif
120
121 +/* There are an extraordinary number of issues with <ctype.h>.
122 + The last straw is that it varies with the locale. Use libiberty's
123 + replacement instead. */
124 +#include "safe-ctype.h"
125 +
126 +#include <sys/types.h>
127 +
128 +#include <errno.h>
129 +
130 +#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
131 +extern int errno;
132 +#endif
133 +
134 /* Some of glibc's string inlines cause warnings. Plus we'd rather
135 rely on (and therefore test) GCC's string builtins. */
136 #define __NO_STRING_INLINES
137 --
138 2.39.3
139