View | Details | Return to bug 23479 | Differences between
and this patch

Collapse All | Expand All

(-)./gcc/doc/extend.texi.orig (+23 lines)
Lines 79-84 Link Here
79
* Pragmas::             Pragmas accepted by GCC.
79
* Pragmas::             Pragmas accepted by GCC.
80
* Unnamed Fields::      Unnamed struct/union fields within structs/unions.
80
* Unnamed Fields::      Unnamed struct/union fields within structs/unions.
81
* Thread-Local::        Per-thread variables.
81
* Thread-Local::        Per-thread variables.
82
* Binary constants::    Binary constants using the @samp{0b} prefix.
82
@end menu
83
@end menu
83
84
84
@node Statement Exprs
85
@node Statement Exprs
Lines 9742-9747 Link Here
9742
Non-@code{static} members shall not be @code{__thread}.
9743
Non-@code{static} members shall not be @code{__thread}.
9743
@end quotation
9744
@end quotation
9744
@end itemize
9745
@end itemize
9746
9747
@node Binary constants
9748
@section Binary constants using the @samp{0b} prefix
9749
@cindex Binary constants using the @samp{0b} prefix
9750
9751
Integer constants can be written as binary constants, consisting of a
9752
sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
9753
@samp{0B}.  This is particularly useful in environments that operate a
9754
lot on the bit-level (like microcontrollers).
9755
9756
The following statements are identical:
9757
9758
@smallexample
9759
i =       42;
9760
i =     0x2a;
9761
i =      052;
9762
i = 0b101010;
9763
@end smallexample
9764
9765
The type of these constants follows the same rules as for octal or
9766
hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
9767
can be applied.
9745
9768
9746
@node C++ Extensions
9769
@node C++ Extensions
9747
@chapter Extensions to the C++ Language
9770
@chapter Extensions to the C++ Language
(-)./gcc/testsuite/gcc.dg/binary-constants-1.c.orig (+312 lines)
Line 0 Link Here
1
/* Test for binary integer constants.  */
2
3
/* Derived from: c99-intconst-1.c, bye Joseph Myers <jsm28@cam.ac.uk>.  */
4
/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>.  */
5
/* { dg-do compile } */
6
/* { dg-options "-std=gnu99" } */
7
8
#include <limits.h>
9
10
/* Assertion that constant C is of type T.  */
11
#define ASSERT_CONST_TYPE(C, T)			\
12
	do {					\
13
	  typedef T type;			\
14
	  typedef type **typepp;		\
15
	  typedef __typeof__((C)) ctype;	\
16
	  typedef ctype **ctypepp;		\
17
	  typepp x = 0;				\
18
	  ctypepp y = 0;			\
19
	  x = y;				\
20
	  y = x;				\
21
	} while (0)
22
23
/* (T *) if E is zero, (void *) otherwise.  */
24
#define type_if_not(T, E) __typeof__(0 ? (T *)0 : (void *)(E))
25
26
/* (T *) if E is nonzero, (void *) otherwise.  */
27
#define type_if(T, E) type_if_not(T, !(E))
28
29
/* Combine pointer types, all but one (void *).  */
30
#define type_comb2(T1, T2) __typeof__(0 ? (T1)0 : (T2)0)
31
#define type_comb3(T1, T2, T3) type_comb2(T1, type_comb2(T2, T3))
32
#define type_comb4(T1, T2, T3, T4)				\
33
	type_comb2(T1, type_comb2(T2, type_comb2(T3, T4)))
34
#define type_comb6(T1, T2, T3, T4, T5, T6)				   \
35
	type_comb2(T1,							   \
36
		   type_comb2(T2,					   \
37
			      type_comb2(T3,				   \
38
					 type_comb2(T4,			   \
39
						    type_comb2(T5, T6)))))
40
41
/* (T1 *) if E1, otherwise (T2 *) if E2.  */
42
#define first_of2p(T1, E1, T2, E2) type_comb2(type_if(T1, (E1)),	   \
43
					     type_if(T2, (!(E1) && (E2))))
44
/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3.  */
45
#define first_of3p(T1, E1, T2, E2, T3, E3)			\
46
	type_comb3(type_if(T1, (E1)),				\
47
		   type_if(T2, (!(E1) && (E2))),		\
48
		   type_if(T3, (!(E1) && !(E2) && (E3))))
49
/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3, otherwise
50
   (T4 *) if E4.  */
51
#define first_of4p(T1, E1, T2, E2, T3, E3, T4, E4)			\
52
	type_comb4(type_if(T1, (E1)),					\
53
		   type_if(T2, (!(E1) && (E2))),			\
54
		   type_if(T3, (!(E1) && !(E2) && (E3))),		\
55
		   type_if(T4, (!(E1) && !(E2) && !(E3) && (E4))))
56
/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3, otherwise
57
   (T4 *) if E4, otherwise (T5 *) if E5, otherwise (T6 *) if E6.  */
58
#define first_of6p(T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6)	    \
59
	type_comb6(type_if(T1, (E1)),					    \
60
		   type_if(T2, (!(E1) && (E2))),			    \
61
		   type_if(T3, (!(E1) && !(E2) && (E3))),		    \
62
		   type_if(T4, (!(E1) && !(E2) && !(E3) && (E4))),	    \
63
		   type_if(T5, (!(E1) && !(E2) && !(E3) && !(E4) && (E5))), \
64
		   type_if(T6, (!(E1) && !(E2) && !(E3)			    \
65
				&& !(E4) && !(E5) && (E6))))
66
67
/* Likewise, but return the original type rather than a pointer type.  */
68
#define first_of2(T1, E1, T2, E2)			\
69
	__typeof__(*((first_of2p(T1, (E1), T2, (E2)))0))
70
#define first_of3(T1, E1, T2, E2, T3, E3)				\
71
	__typeof__(*((first_of3p(T1, (E1), T2, (E2), T3, (E3)))0))
72
#define first_of4(T1, E1, T2, E2, T3, E3, T4, E4)			    \
73
	__typeof__(*((first_of4p(T1, (E1), T2, (E2), T3, (E3), T4, (E4)))0))
74
#define first_of6(T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6)	\
75
	__typeof__(*((first_of6p(T1, (E1), T2, (E2), T3, (E3),		\
76
				 T4, (E4), T5, (E5), T6, (E6)))0))
77
78
/* Types of constants according to the C99 rules.  */
79
#define C99_UNSUF_TYPE(C)					\
80
	first_of6(int, (C) <= INT_MAX,				\
81
		  unsigned int, (C) <= UINT_MAX,		\
82
		  long int, (C) <= LONG_MAX,			\
83
		  unsigned long int, (C) <= ULONG_MAX,		\
84
		  long long int, (C) <= LLONG_MAX,		\
85
		  unsigned long long int, (C) <= ULLONG_MAX)
86
#define C99_SUFu_TYPE(C)					\
87
	first_of3(unsigned int, (C) <= UINT_MAX,		\
88
		  unsigned long int, (C) <= ULONG_MAX,		\
89
		  unsigned long long int, (C) <= ULLONG_MAX)
90
#define C99_SUFl_TYPE(C)					\
91
	first_of4(long int, (C) <= LONG_MAX,			\
92
		  unsigned long int, (C) <= ULONG_MAX,		\
93
		  long long int, (C) <= LLONG_MAX,		\
94
		  unsigned long long int, (C) <= ULLONG_MAX)
95
#define C99_SUFul_TYPE(C)					\
96
	first_of2(unsigned long int, (C) <= ULONG_MAX,		\
97
		  unsigned long long int, (C) <= ULLONG_MAX)
98
#define C99_SUFll_TYPE(C)					\
99
	first_of2(long long int, (C) <= LLONG_MAX,		\
100
		  unsigned long long int, (C) <= ULLONG_MAX)
101
102
/* Checks that constants have correct type.  */
103
#define CHECK_UNSUF_TYPE(C)				\
104
	ASSERT_CONST_TYPE((C), C99_UNSUF_TYPE((C)))
105
#define CHECK_SUFu_TYPE(C) ASSERT_CONST_TYPE((C), C99_SUFu_TYPE((C)))
106
#define CHECK_SUFl_TYPE(C)				\
107
	ASSERT_CONST_TYPE((C), C99_SUFl_TYPE((C)))
108
#define CHECK_SUFul_TYPE(C) ASSERT_CONST_TYPE((C), C99_SUFul_TYPE((C)))
109
#define CHECK_SUFll_TYPE(C)				\
110
	ASSERT_CONST_TYPE((C), C99_SUFll_TYPE((C)))
111
#define CHECK_SUFull_TYPE(C) ASSERT_CONST_TYPE((C), unsigned long long int)
112
113
/* Check an octal or hexadecimal value, with all suffixes.  */
114
#define CHECK_CONST(C)                  	\
115
	CHECK_UNSUF_TYPE(C);                    \
116
	CHECK_SUFu_TYPE(C##u);			\
117
	CHECK_SUFu_TYPE(C##U);			\
118
	CHECK_SUFl_TYPE(C##l);                  \
119
	CHECK_SUFl_TYPE(C##L);                  \
120
	CHECK_SUFul_TYPE(C##ul);		\
121
	CHECK_SUFul_TYPE(C##uL);		\
122
	CHECK_SUFul_TYPE(C##Ul);		\
123
	CHECK_SUFul_TYPE(C##UL);		\
124
	CHECK_SUFll_TYPE(C##ll);		\
125
	CHECK_SUFll_TYPE(C##LL);		\
126
	CHECK_SUFull_TYPE(C##ull);		\
127
	CHECK_SUFull_TYPE(C##uLL);		\
128
	CHECK_SUFull_TYPE(C##Ull);		\
129
	CHECK_SUFull_TYPE(C##ULL);
130
131
#define CHECK_BIN_CONST(C)			\
132
	CHECK_CONST(0b##C);                     \
133
	CHECK_CONST(0B##C);
134
135
/* True iff "long long" is at least B bits.  This presumes that (B-2)/3 is at
136
   most 63.  */
137
#define LLONG_AT_LEAST(B)			\
138
	(LLONG_MAX >> ((B)-2)/3 >> ((B)-2)/3	\
139
	 >> ((B)-2 - ((B)-2)/3 - ((B)-2)/3))
140
141
#define LLONG_HAS_BITS(B) (LLONG_AT_LEAST((B)) && !LLONG_AT_LEAST((B) + 1))
142
143
#define FOO 0b1101
144
#if !FOO
145
# error "preprocessor does not accept binary constants"
146
#endif
147
148
void
149
foo (void)
150
{
151
  /* Check all 2^n and 2^n - 1 up to 2^72 - 1.  */
152
  CHECK_BIN_CONST(1);
153
  CHECK_BIN_CONST(10);
154
  CHECK_BIN_CONST(11);
155
  CHECK_BIN_CONST(100);
156
  CHECK_BIN_CONST(111);
157
  CHECK_BIN_CONST(1000);
158
  CHECK_BIN_CONST(1111);
159
  CHECK_BIN_CONST(10000);
160
  CHECK_BIN_CONST(11111);
161
  CHECK_BIN_CONST(100000);
162
  CHECK_BIN_CONST(111111);
163
  CHECK_BIN_CONST(1000000);
164
  CHECK_BIN_CONST(1111111);
165
  CHECK_BIN_CONST(10000000);
166
  CHECK_BIN_CONST(11111111);
167
  CHECK_BIN_CONST(100000000);
168
  CHECK_BIN_CONST(111111111);
169
  CHECK_BIN_CONST(1000000000);
170
  CHECK_BIN_CONST(1111111111);
171
  CHECK_BIN_CONST(10000000000);
172
  CHECK_BIN_CONST(11111111111);
173
  CHECK_BIN_CONST(100000000000);
174
  CHECK_BIN_CONST(111111111111);
175
  CHECK_BIN_CONST(1000000000000);
176
  CHECK_BIN_CONST(1111111111111);
177
  CHECK_BIN_CONST(10000000000000);
178
  CHECK_BIN_CONST(11111111111111);
179
  CHECK_BIN_CONST(100000000000000);
180
  CHECK_BIN_CONST(111111111111111);
181
  CHECK_BIN_CONST(1000000000000000);
182
  CHECK_BIN_CONST(1111111111111111);
183
  CHECK_BIN_CONST(10000000000000000);
184
  CHECK_BIN_CONST(11111111111111111);
185
  CHECK_BIN_CONST(100000000000000000);
186
  CHECK_BIN_CONST(111111111111111111);
187
  CHECK_BIN_CONST(1000000000000000000);
188
  CHECK_BIN_CONST(1111111111111111111);
189
  CHECK_BIN_CONST(10000000000000000000);
190
  CHECK_BIN_CONST(11111111111111111111);
191
  CHECK_BIN_CONST(100000000000000000000);
192
  CHECK_BIN_CONST(111111111111111111111);
193
  CHECK_BIN_CONST(1000000000000000000000);
194
  CHECK_BIN_CONST(1111111111111111111111);
195
  CHECK_BIN_CONST(10000000000000000000000);
196
  CHECK_BIN_CONST(11111111111111111111111);
197
  CHECK_BIN_CONST(100000000000000000000000);
198
  CHECK_BIN_CONST(111111111111111111111111);
199
  CHECK_BIN_CONST(1000000000000000000000000);
200
  CHECK_BIN_CONST(1111111111111111111111111);
201
  CHECK_BIN_CONST(10000000000000000000000000);
202
  CHECK_BIN_CONST(11111111111111111111111111);
203
  CHECK_BIN_CONST(100000000000000000000000000);
204
  CHECK_BIN_CONST(111111111111111111111111111);
205
  CHECK_BIN_CONST(1000000000000000000000000000);
206
  CHECK_BIN_CONST(1111111111111111111111111111);
207
  CHECK_BIN_CONST(10000000000000000000000000000);
208
  CHECK_BIN_CONST(11111111111111111111111111111);
209
  CHECK_BIN_CONST(100000000000000000000000000000);
210
  CHECK_BIN_CONST(111111111111111111111111111111);
211
  CHECK_BIN_CONST(1000000000000000000000000000000);
212
  CHECK_BIN_CONST(1111111111111111111111111111111);
213
  CHECK_BIN_CONST(10000000000000000000000000000000);
214
  CHECK_BIN_CONST(11111111111111111111111111111111);
215
  CHECK_BIN_CONST(100000000000000000000000000000000);
216
  CHECK_BIN_CONST(111111111111111111111111111111111);
217
  CHECK_BIN_CONST(1000000000000000000000000000000000);
218
  CHECK_BIN_CONST(1111111111111111111111111111111111);
219
  CHECK_BIN_CONST(10000000000000000000000000000000000);
220
  CHECK_BIN_CONST(11111111111111111111111111111111111);
221
  CHECK_BIN_CONST(100000000000000000000000000000000000);
222
  CHECK_BIN_CONST(111111111111111111111111111111111111);
223
  CHECK_BIN_CONST(1000000000000000000000000000000000000);
224
  CHECK_BIN_CONST(1111111111111111111111111111111111111);
225
  CHECK_BIN_CONST(10000000000000000000000000000000000000);
226
  CHECK_BIN_CONST(11111111111111111111111111111111111111);
227
  CHECK_BIN_CONST(100000000000000000000000000000000000000);
228
  CHECK_BIN_CONST(111111111111111111111111111111111111111);
229
  CHECK_BIN_CONST(1000000000000000000000000000000000000000);
230
  CHECK_BIN_CONST(1111111111111111111111111111111111111111);
231
  CHECK_BIN_CONST(10000000000000000000000000000000000000000);
232
  CHECK_BIN_CONST(11111111111111111111111111111111111111111);
233
  CHECK_BIN_CONST(100000000000000000000000000000000000000000);
234
  CHECK_BIN_CONST(111111111111111111111111111111111111111111);
235
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000);
236
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111);
237
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000);
238
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111);
239
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000);
240
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111);
241
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000);
242
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111);
243
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000);
244
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111);
245
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000);
246
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111);
247
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000);
248
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111);
249
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000);
250
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111);
251
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000);
252
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111);
253
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000);
254
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111);
255
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000);
256
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111);
257
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000);
258
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111);
259
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000);
260
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111);
261
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000);
262
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111);
263
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000);
264
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111);
265
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000);
266
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111);
267
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000);
268
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111);
269
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000);
270
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111);
271
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000000);
272
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111111);
273
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000000);
274
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111111);
275
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000000);
276
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111111);
277
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000000000);
278
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111111111);
279
#if LLONG_AT_LEAST(65)
280
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000000000);
281
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111111111);
282
#endif
283
#if LLONG_AT_LEAST(66)
284
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000000000);
285
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111111111);
286
#endif
287
#if LLONG_AT_LEAST(67)
288
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000000000000);
289
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111111111111);
290
#endif
291
#if LLONG_AT_LEAST(68)
292
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000000000000);
293
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111111111111);
294
#endif
295
#if LLONG_AT_LEAST(69)
296
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000000000000);
297
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111111111111);
298
#endif
299
#if LLONG_AT_LEAST(70)
300
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000000000000000);
301
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111111111111111);
302
#endif
303
#if LLONG_AT_LEAST(71)
304
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000000000000000);
305
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111111111111111);
306
#endif
307
#if LLONG_AT_LEAST(72)
308
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000000000000000);
309
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111111111111111);
310
#endif
311
}
312
(-)./gcc/testsuite/gcc.dg/binary-constants-2.c.orig (+16 lines)
Line 0 Link Here
1
/* Test for binary integer constants: -pedantic warnings.  */
2
3
/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>.  */
4
/* { dg-do compile } */
5
/* { dg-options "-std=iso9899:1999 -pedantic" } */
6
7
#define FOO 0b1101
8
9
int
10
foo (void)
11
{
12
#if FOO /* { dg-warning "binary constants are a GCC extension" } */
13
  return 23;
14
#endif
15
  return 0b1101; /* { dg-warning "binary constants are a GCC extension" } */
16
}
(-)./gcc/testsuite/gcc.dg/binary-constants-3.c.orig (+16 lines)
Line 0 Link Here
1
/* Test for binary integer constants: -pedantic-errors.  */
2
3
/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>.  */
4
/* { dg-do compile } */
5
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
6
7
#define FOO 0b1101
8
9
int
10
foo (void)
11
{
12
#if FOO /* { dg-error "binary constants are a GCC extension" } */
13
  return 23;
14
#endif
15
  return 0b1101; /* { dg-error "binary constants are a GCC extension" } */
16
}
(-)./gcc/testsuite/gcc.dg/binary-constants-4.c.orig (+18 lines)
Line 0 Link Here
1
/* Test for binary integer constants: random errors.  */
2
3
/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>.  */
4
/* { dg-do compile } */
5
/* { dg-options "-std=gnu99" } */
6
7
void
8
foo(void)
9
{
10
  double d;
11
  int i;
12
13
  d = 0b1101;
14
  d = 0b1101p1; /* { dg-error "invalid suffix \"p1\" on integer constant" } */
15
  d = 0x1101p1;
16
  i = 0b3011;   /* { dg-error "invalid suffix \"b3011\" on integer constant" } */
17
  i = 0b113;    /* { dg-error "invalid digit \"3\" in binary constant" } */
18
}
(-)./libcpp/include/cpplib.h.orig (+1 lines)
Lines 729-734 Link Here
729
#define CPP_N_DECIMAL	0x0100
729
#define CPP_N_DECIMAL	0x0100
730
#define CPP_N_HEX	0x0200
730
#define CPP_N_HEX	0x0200
731
#define CPP_N_OCTAL	0x0400
731
#define CPP_N_OCTAL	0x0400
732
#define CPP_N_BINARY	0x0800
732
733
733
#define CPP_N_UNSIGNED	0x1000	/* Properties.  */
734
#define CPP_N_UNSIGNED	0x1000	/* Properties.  */
734
#define CPP_N_IMAGINARY	0x2000
735
#define CPP_N_IMAGINARY	0x2000
(-)./libcpp/expr.c.orig (-3 / +43 lines)
Lines 171-176 Link Here
171
	  radix = 16;
171
	  radix = 16;
172
	  str++;
172
	  str++;
173
	}
173
	}
174
      else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1'))
175
	{
176
	  radix = 2;
177
	  str++;
178
	}
174
    }
179
    }
175
180
176
  /* Now scan for a well-formed integer or float.  */
181
  /* Now scan for a well-formed integer or float.  */
Lines 209-218 Link Here
209
    radix = 10;
214
    radix = 10;
210
215
211
  if (max_digit >= radix)
216
  if (max_digit >= radix)
212
    SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
217
    {
218
      if (radix == 2)
219
	SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit);
220
      else
221
	SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
222
    }
213
223
214
  if (float_flag != NOT_FLOAT)
224
  if (float_flag != NOT_FLOAT)
215
    {
225
    {
226
      if (radix == 2)
227
	{
228
	  cpp_error (pfile, CPP_DL_ERROR,
229
		     "invalid prefix \"0b\" for floating constant");
230
	  return CPP_N_INVALID;
231
	}
232
216
      if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
233
      if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
217
	cpp_error (pfile, CPP_DL_PEDWARN,
234
	cpp_error (pfile, CPP_DL_PEDWARN,
218
		   "use of C99 hexadecimal floating constant");
235
		   "use of C99 hexadecimal floating constant");
Lines 288-298 Link Here
288
  if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
305
  if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
289
    cpp_error (pfile, CPP_DL_PEDWARN,
306
    cpp_error (pfile, CPP_DL_PEDWARN,
290
	       "imaginary constants are a GCC extension");
307
	       "imaginary constants are a GCC extension");
308
  if (radix == 2 && CPP_PEDANTIC (pfile))
309
    cpp_error (pfile, CPP_DL_PEDWARN,
310
	       "binary constants are a GCC extension");
291
311
292
  if (radix == 10)
312
  if (radix == 10)
293
    result |= CPP_N_DECIMAL;
313
    result |= CPP_N_DECIMAL;
294
  else if (radix == 16)
314
  else if (radix == 16)
295
    result |= CPP_N_HEX;
315
    result |= CPP_N_HEX;
316
  else if (radix == 2)
317
    result |= CPP_N_BINARY;
296
  else
318
  else
297
    result |= CPP_N_OCTAL;
319
    result |= CPP_N_OCTAL;
298
320
Lines 343-348 Link Here
343
	  base = 16;
365
	  base = 16;
344
	  p += 2;
366
	  p += 2;
345
	}
367
	}
368
      else if ((type & CPP_N_RADIX) == CPP_N_BINARY)
369
	{
370
	  base = 2;
371
	  p += 2;
372
	}
346
373
347
      /* We can add a digit to numbers strictly less than this without
374
      /* We can add a digit to numbers strictly less than this without
348
	 needing the precision and slowness of double integers.  */
375
	 needing the precision and slowness of double integers.  */
Lines 398-409 Link Here
398
append_digit (cpp_num num, int digit, int base, size_t precision)
425
append_digit (cpp_num num, int digit, int base, size_t precision)
399
{
426
{
400
  cpp_num result;
427
  cpp_num result;
401
  unsigned int shift = 3 + (base == 16);
428
  unsigned int shift;
402
  bool overflow;
429
  bool overflow;
403
  cpp_num_part add_high, add_low;
430
  cpp_num_part add_high, add_low;
404
431
405
  /* Multiply by 8 or 16.  Catching this overflow here means we don't
432
  /* Multiply by 2, 8 or 16.  Catching this overflow here means we don't
406
     need to worry about add_high overflowing.  */
433
     need to worry about add_high overflowing.  */
434
  switch (base)
435
    {
436
    case 2:
437
      shift = 1;
438
      break;
439
440
    case 16:
441
      shift = 4;
442
      break;
443
444
    default:
445
      shift = 3;
446
    }
407
  overflow = !!(num.high >> (PART_PRECISION - shift));
447
  overflow = !!(num.high >> (PART_PRECISION - shift));
408
  result.high = num.high << shift;
448
  result.high = num.high << shift;
409
  result.low = num.low << shift;
449
  result.low = num.low << shift;

Return to bug 23479