View | Details | Raw Unified | Return to bug 7263 | Differences between
and this patch

Collapse All | Expand All

(-)a/gcc/c-decl.c (-7 / +8 lines)
Lines 9436-9442 declspecs_add_attrs (struct c_declspecs *specs, tree attrs) Link Here
9436
   double".  */
9436
   double".  */
9437
9437
9438
struct c_declspecs *
9438
struct c_declspecs *
9439
finish_declspecs (struct c_declspecs *specs)
9439
finish_declspecs (struct c_declspecs *specs,
9440
		  location_t where)
9440
{
9441
{
9441
  /* If a type was specified as a whole, we have no modifiers and are
9442
  /* If a type was specified as a whole, we have no modifiers and are
9442
     done.  */
9443
     done.  */
Lines 9457-9465 finish_declspecs (struct c_declspecs *specs) Link Here
9457
    {
9458
    {
9458
      if (specs->saturating_p)
9459
      if (specs->saturating_p)
9459
	{
9460
	{
9460
	  error ("%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
9461
	  error_at (where, "%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
9461
	  if (!targetm.fixed_point_supported_p ())
9462
	  if (!targetm.fixed_point_supported_p ())
9462
	    error ("fixed-point types not supported for this target");
9463
	    error_at (where, "fixed-point types not supported for this target");
9463
	  specs->typespec_word = cts_fract;
9464
	  specs->typespec_word = cts_fract;
9464
	}
9465
	}
9465
      else if (specs->long_p || specs->short_p
9466
      else if (specs->long_p || specs->short_p
Lines 9470-9476 finish_declspecs (struct c_declspecs *specs) Link Here
9470
      else if (specs->complex_p)
9471
      else if (specs->complex_p)
9471
	{
9472
	{
9472
	  specs->typespec_word = cts_double;
9473
	  specs->typespec_word = cts_double;
9473
	  pedwarn (input_location, OPT_pedantic,
9474
	  pedwarn (where, OPT_pedantic,
9474
		   "ISO C does not support plain %<complex%> meaning "
9475
		   "ISO C does not support plain %<complex%> meaning "
9475
		   "%<double complex%>");
9476
		   "%<double complex%>");
9476
	}
9477
	}
Lines 9515-9521 finish_declspecs (struct c_declspecs *specs) Link Here
9515
	specs->type = char_type_node;
9516
	specs->type = char_type_node;
9516
      if (specs->complex_p)
9517
      if (specs->complex_p)
9517
	{
9518
	{
9518
	  pedwarn (input_location, OPT_pedantic,
9519
	  pedwarn (where, OPT_pedantic,
9519
		   "ISO C does not support complex integer types");
9520
		   "ISO C does not support complex integer types");
9520
	  specs->type = build_complex_type (specs->type);
9521
	  specs->type = build_complex_type (specs->type);
9521
	}
9522
	}
Lines 9528-9534 finish_declspecs (struct c_declspecs *specs) Link Here
9528
		     : int128_integer_type_node);
9529
		     : int128_integer_type_node);
9529
      if (specs->complex_p)
9530
      if (specs->complex_p)
9530
	{
9531
	{
9531
	  pedwarn (input_location, OPT_pedantic,
9532
	  pedwarn (where, OPT_pedantic,
9532
		   "ISO C does not support complex integer types");
9533
		   "ISO C does not support complex integer types");
9533
	  specs->type = build_complex_type (specs->type);
9534
	  specs->type = build_complex_type (specs->type);
9534
	}
9535
	}
Lines 9554-9560 finish_declspecs (struct c_declspecs *specs) Link Here
9554
		       : integer_type_node);
9555
		       : integer_type_node);
9555
      if (specs->complex_p)
9556
      if (specs->complex_p)
9556
	{
9557
	{
9557
	  pedwarn (input_location, OPT_pedantic,
9558
	  pedwarn (where, OPT_pedantic,
9558
		   "ISO C does not support complex integer types");
9559
		   "ISO C does not support complex integer types");
9559
	  specs->type = build_complex_type (specs->type);
9560
	  specs->type = build_complex_type (specs->type);
9560
	}
9561
	}
(-)a/gcc/c-family/c-lex.c (-1 / +1 lines)
Lines 316-322 c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here
316
316
317
    case CPP_NUMBER:
317
    case CPP_NUMBER:
318
      {
318
      {
319
	unsigned int flags = cpp_classify_number (parse_in, tok);
319
	unsigned int flags = cpp_classify_number (parse_in, tok, *loc);
320
320
321
	switch (flags & CPP_N_CATEGORY)
321
	switch (flags & CPP_N_CATEGORY)
322
	  {
322
	  {
(-)a/gcc/c-parser.c (-4 / +8 lines)
Lines 1437-1443 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, Link Here
1437
      c_parser_skip_to_end_of_block_or_statement (parser);
1437
      c_parser_skip_to_end_of_block_or_statement (parser);
1438
      return;
1438
      return;
1439
    }
1439
    }
1440
  finish_declspecs (specs);
1440
  finish_declspecs (specs, here);
1441
  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1441
  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1442
    {
1442
    {
1443
      if (empty_ok)
1443
      if (empty_ok)
Lines 2506-2512 c_parser_struct_declaration (c_parser *parser) Link Here
2506
      c_parser_error (parser, "expected specifier-qualifier-list");
2506
      c_parser_error (parser, "expected specifier-qualifier-list");
2507
      return NULL_TREE;
2507
      return NULL_TREE;
2508
    }
2508
    }
2509
  finish_declspecs (specs);
2509
  finish_declspecs (specs, decl_loc);
2510
  if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2510
  if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2511
      || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2511
      || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2512
    {
2512
    {
Lines 3172-3177 c_parser_parameter_declaration (c_parser *parser, tree attrs) Link Here
3172
  tree prefix_attrs;
3172
  tree prefix_attrs;
3173
  tree postfix_attrs = NULL_TREE;
3173
  tree postfix_attrs = NULL_TREE;
3174
  bool dummy = false;
3174
  bool dummy = false;
3175
  location_t here = c_parser_peek_token (parser)->location;
3176
3175
  if (!c_parser_next_token_starts_declspecs (parser))
3177
  if (!c_parser_next_token_starts_declspecs (parser))
3176
    {
3178
    {
3177
      c_token *token = c_parser_peek_token (parser);
3179
      c_token *token = c_parser_peek_token (parser);
Lines 3200-3206 c_parser_parameter_declaration (c_parser *parser, tree attrs) Link Here
3200
      attrs = NULL_TREE;
3202
      attrs = NULL_TREE;
3201
    }
3203
    }
3202
  c_parser_declspecs (parser, specs, true, true, true);
3204
  c_parser_declspecs (parser, specs, true, true, true);
3203
  finish_declspecs (specs);
3205
  finish_declspecs (specs, here);
3204
  pending_xref_error ();
3206
  pending_xref_error ();
3205
  prefix_attrs = specs->attrs;
3207
  prefix_attrs = specs->attrs;
3206
  specs->attrs = NULL_TREE;
3208
  specs->attrs = NULL_TREE;
Lines 3489-3494 c_parser_type_name (c_parser *parser) Link Here
3489
  struct c_declarator *declarator;
3491
  struct c_declarator *declarator;
3490
  struct c_type_name *ret;
3492
  struct c_type_name *ret;
3491
  bool dummy = false;
3493
  bool dummy = false;
3494
  location_t here = c_parser_peek_token (parser)->location;
3495
3492
  c_parser_declspecs (parser, specs, false, true, true);
3496
  c_parser_declspecs (parser, specs, false, true, true);
3493
  if (!specs->declspecs_seen_p)
3497
  if (!specs->declspecs_seen_p)
3494
    {
3498
    {
Lines 3496-3502 c_parser_type_name (c_parser *parser) Link Here
3496
      return NULL;
3500
      return NULL;
3497
    }
3501
    }
3498
  pending_xref_error ();
3502
  pending_xref_error ();
3499
  finish_declspecs (specs);
3503
  finish_declspecs (specs, here);
3500
  declarator = c_parser_declarator (parser,
3504
  declarator = c_parser_declarator (parser,
3501
				    specs->typespec_kind != ctsk_none,
3505
				    specs->typespec_kind != ctsk_none,
3502
				    C_DTR_ABSTRACT, &dummy);
3506
				    C_DTR_ABSTRACT, &dummy);
(-)a/gcc/c-tree.h (-1 / +1 lines)
Lines 491-497 extern struct c_declspecs *declspecs_add_scspec (struct c_declspecs *, tree); Link Here
491
extern struct c_declspecs *declspecs_add_attrs (struct c_declspecs *, tree);
491
extern struct c_declspecs *declspecs_add_attrs (struct c_declspecs *, tree);
492
extern struct c_declspecs *declspecs_add_addrspace (struct c_declspecs *,
492
extern struct c_declspecs *declspecs_add_addrspace (struct c_declspecs *,
493
						    addr_space_t);
493
						    addr_space_t);
494
extern struct c_declspecs *finish_declspecs (struct c_declspecs *);
494
extern struct c_declspecs *finish_declspecs (struct c_declspecs *, location_t);
495
495
496
/* in c-objc-common.c */
496
/* in c-objc-common.c */
497
extern bool c_objc_common_init (void);
497
extern bool c_objc_common_init (void);
(-)a/gcc/testsuite/gcc.dg/cpp/syshdr3.c (+16 lines)
Line 0 Link Here
1
/* Contributed by Dodji Seketeli <dodji@redhat.com> */
2
/* Origin: PR preprocessor/7263 */
3
/* { dg-options "-pedantic -std=c89 -ftrack-macro-expansion=1" } */
4
/* { dg-do compile } */
5
6
/* This tests the proprer suppression of warning coming from macro
7
   defined in system headers and expanded in a non-system header
8
   location.  */
9
#include "syshdr3.h"
10
11
_Complex c = _Complex_I + _Complex_I; /* These macros are defined in
12
					 system header so we should
13
					 have no warning here.  */
14
U_LL u = ONE_ULL; /* Likewise here.  */
15
16
unsigned long long v = 1ULL; /* { dg-warning "long long" } */
(-)a/gcc/testsuite/gcc.dg/cpp/syshdr3.h (+7 lines)
Line 0 Link Here
1
#pragma GCC system_header
2
3
#define _Complex __complex__
4
#define _Complex_I 1.0iF
5
6
#define U_LL unsigned long long
7
#define ONE_ULL 1ULL
(-)a/libcpp/errors.c (-20 / +1 lines)
Lines 38-63 cpp_diagnostic (cpp_reader * pfile, int level, int reason, Link Here
38
  source_location src_loc;
38
  source_location src_loc;
39
  bool ret;
39
  bool ret;
40
40
41
  if (CPP_OPTION (pfile, traditional))
41
  src_loc = _cpp_get_prev_token_spelling_loc (pfile);
42
    {
43
      if (pfile->state.in_directive)
44
	src_loc = pfile->directive_line;
45
      else
46
	src_loc = LINEMAPS_ORDINARY_HIGHEST_LINE (pfile->line_table);
47
    }
48
  /* We don't want to refer to a token before the beginning of the
49
     current run -- that is invalid.  */
50
  else if (pfile->cur_token == pfile->cur_run->base)
51
    {
52
      if (pfile->cur_run->prev != NULL)
53
	src_loc = pfile->cur_run->prev->limit->src_loc;
54
      else
55
	src_loc = 0;
56
    }
57
  else
58
    {
59
      src_loc = pfile->cur_token[-1].src_loc;
60
    }
61
42
62
  if (!pfile->cb.error)
43
  if (!pfile->cb.error)
63
    abort ();
44
    abort ();
(-)a/libcpp/expr.c (-72 / +104 lines)
Lines 59-65 static cpp_num num_rshift (cpp_num, size_t, size_t); Link Here
59
59
60
static cpp_num append_digit (cpp_num, int, int, size_t);
60
static cpp_num append_digit (cpp_num, int, int, size_t);
61
static cpp_num parse_defined (cpp_reader *);
61
static cpp_num parse_defined (cpp_reader *);
62
static cpp_num eval_token (cpp_reader *, const cpp_token *);
62
static cpp_num eval_token (cpp_reader *, const cpp_token *, source_location);
63
static struct op *reduce (cpp_reader *, struct op *, enum cpp_ttype);
63
static struct op *reduce (cpp_reader *, struct op *, enum cpp_ttype);
64
static unsigned int interpret_float_suffix (const uchar *, size_t);
64
static unsigned int interpret_float_suffix (const uchar *, size_t);
65
static unsigned int interpret_int_suffix (const uchar *, size_t);
65
static unsigned int interpret_int_suffix (const uchar *, size_t);
Lines 76-81 static void check_promotion (cpp_reader *, const struct op *); Link Here
76
#define SYNTAX_ERROR2(msgid, arg) \
76
#define SYNTAX_ERROR2(msgid, arg) \
77
  do { cpp_error (pfile, CPP_DL_ERROR, msgid, arg); goto syntax_error; } \
77
  do { cpp_error (pfile, CPP_DL_ERROR, msgid, arg); goto syntax_error; } \
78
  while(0)
78
  while(0)
79
#define SYNTAX_ERROR_AT(loc, msgid) \
80
  do { cpp_error_with_line (pfile, CPP_DL_ERROR, (loc), 0, msgid); goto syntax_error; } \
81
  while(0)
82
#define SYNTAX_ERROR2_AT(loc, msgid, arg)					\
83
  do { cpp_error_with_line (pfile, CPP_DL_ERROR, (loc), 0, msgid, arg); goto syntax_error; } \
84
  while(0)
79
85
80
/* Subroutine of cpp_classify_number.  S points to a float suffix of
86
/* Subroutine of cpp_classify_number.  S points to a float suffix of
81
   length LEN, possibly zero.  Returns 0 for an invalid suffix, or a
87
   length LEN, possibly zero.  Returns 0 for an invalid suffix, or a
Lines 223-229 interpret_int_suffix (const uchar *s, size_t len) Link Here
223
   floating point, or invalid), radix (decimal, octal, hexadecimal),
229
   floating point, or invalid), radix (decimal, octal, hexadecimal),
224
   and type suffixes.  */
230
   and type suffixes.  */
225
unsigned int
231
unsigned int
226
cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
232
cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
233
		     source_location virtual_location)
227
{
234
{
228
  const uchar *str = token->val.str.text;
235
  const uchar *str = token->val.str.text;
229
  const uchar *limit;
236
  const uchar *limit;
Lines 279-285 cpp_classify_number (cpp_reader *pfile, const cpp_token *token) Link Here
279
	  if (float_flag == NOT_FLOAT)
286
	  if (float_flag == NOT_FLOAT)
280
	    float_flag = AFTER_POINT;
287
	    float_flag = AFTER_POINT;
281
	  else
288
	  else
282
	    SYNTAX_ERROR ("too many decimal points in number");
289
	    SYNTAX_ERROR_AT (virtual_location,
290
			     "too many decimal points in number");
283
	}
291
	}
284
      else if ((radix <= 10 && (c == 'e' || c == 'E'))
292
      else if ((radix <= 10 && (c == 'e' || c == 'E'))
285
	       || (radix == 16 && (c == 'p' || c == 'P')))
293
	       || (radix == 16 && (c == 'p' || c == 'P')))
Lines 307-314 cpp_classify_number (cpp_reader *pfile, const cpp_token *token) Link Here
307
	    radix = 10;
315
	    radix = 10;
308
316
309
	  if (CPP_PEDANTIC (pfile))
317
	  if (CPP_PEDANTIC (pfile))
310
	    cpp_error (pfile, CPP_DL_PEDWARN,
318
	    cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
311
		       "fixed-point constants are a GCC extension");
319
				 "fixed-point constants are a GCC extension");
312
	  goto syntax_ok;
320
	  goto syntax_ok;
313
	}
321
	}
314
      else
322
      else
Lines 321-346 cpp_classify_number (cpp_reader *pfile, const cpp_token *token) Link Here
321
  if (max_digit >= radix)
329
  if (max_digit >= radix)
322
    {
330
    {
323
      if (radix == 2)
331
      if (radix == 2)
324
	SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit);
332
	SYNTAX_ERROR2_AT (virtual_location,
333
			  "invalid digit \"%c\" in binary constant", '0' + max_digit);
325
      else
334
      else
326
	SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
335
	SYNTAX_ERROR2_AT (virtual_location,
336
			  "invalid digit \"%c\" in octal constant", '0' + max_digit);
327
    }
337
    }
328
338
329
  if (float_flag != NOT_FLOAT)
339
  if (float_flag != NOT_FLOAT)
330
    {
340
    {
331
      if (radix == 2)
341
      if (radix == 2)
332
	{
342
	{
333
	  cpp_error (pfile, CPP_DL_ERROR,
343
	  cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
334
		     "invalid prefix \"0b\" for floating constant");
344
			       "invalid prefix \"0b\" for floating constant");
335
	  return CPP_N_INVALID;
345
	  return CPP_N_INVALID;
336
	}
346
	}
337
347
338
      if (radix == 16 && !seen_digit)
348
      if (radix == 16 && !seen_digit)
339
	SYNTAX_ERROR ("no digits in hexadecimal floating constant");
349
	SYNTAX_ERROR_AT (virtual_location,
350
			 "no digits in hexadecimal floating constant");
340
351
341
      if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
352
      if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
342
	cpp_error (pfile, CPP_DL_PEDWARN,
353
	cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
343
		   "use of C99 hexadecimal floating constant");
354
			     "use of C99 hexadecimal floating constant");
344
355
345
      if (float_flag == AFTER_EXPON)
356
      if (float_flag == AFTER_EXPON)
346
	{
357
	{
Lines 349-369 cpp_classify_number (cpp_reader *pfile, const cpp_token *token) Link Here
349
360
350
	  /* Exponent is decimal, even if string is a hex float.  */
361
	  /* Exponent is decimal, even if string is a hex float.  */
351
	  if (!ISDIGIT (*str))
362
	  if (!ISDIGIT (*str))
352
	    SYNTAX_ERROR ("exponent has no digits");
363
	    SYNTAX_ERROR_AT (virtual_location, "exponent has no digits");
353
364
354
	  do
365
	  do
355
	    str++;
366
	    str++;
356
	  while (ISDIGIT (*str));
367
	  while (ISDIGIT (*str));
357
	}
368
	}
358
      else if (radix == 16)
369
      else if (radix == 16)
359
	SYNTAX_ERROR ("hexadecimal floating constants require an exponent");
370
	SYNTAX_ERROR_AT (virtual_location,
371
			 "hexadecimal floating constants require an exponent");
360
372
361
      result = interpret_float_suffix (str, limit - str);
373
      result = interpret_float_suffix (str, limit - str);
362
      if (result == 0)
374
      if (result == 0)
363
	{
375
	{
364
	  cpp_error (pfile, CPP_DL_ERROR,
376
	  cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
365
		     "invalid suffix \"%.*s\" on floating constant",
377
			       "invalid suffix \"%.*s\" on floating constant",
366
		     (int) (limit - str), str);
378
			       (int) (limit - str), str);
367
	  return CPP_N_INVALID;
379
	  return CPP_N_INVALID;
368
	}
380
	}
369
381
Lines 371-403 cpp_classify_number (cpp_reader *pfile, const cpp_token *token) Link Here
371
      if (limit != str
383
      if (limit != str
372
	  && CPP_WTRADITIONAL (pfile)
384
	  && CPP_WTRADITIONAL (pfile)
373
	  && ! cpp_sys_macro_p (pfile))
385
	  && ! cpp_sys_macro_p (pfile))
374
	cpp_warning (pfile, CPP_W_TRADITIONAL,
386
	cpp_warning_with_line (pfile, CPP_W_TRADITIONAL, virtual_location, 0,
375
		     "traditional C rejects the \"%.*s\" suffix",
387
			       "traditional C rejects the \"%.*s\" suffix",
376
		     (int) (limit - str), str);
388
			       (int) (limit - str), str);
377
389
378
      /* A suffix for double is a GCC extension via decimal float support.
390
      /* A suffix for double is a GCC extension via decimal float support.
379
	 If the suffix also specifies an imaginary value we'll catch that
391
	 If the suffix also specifies an imaginary value we'll catch that
380
	 later.  */
392
	 later.  */
381
      if ((result == CPP_N_MEDIUM) && CPP_PEDANTIC (pfile))
393
      if ((result == CPP_N_MEDIUM) && CPP_PEDANTIC (pfile))
382
	cpp_error (pfile, CPP_DL_PEDWARN,
394
	cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
383
		   "suffix for double constant is a GCC extension");
395
			     "suffix for double constant is a GCC extension");
384
396
385
      /* Radix must be 10 for decimal floats.  */
397
      /* Radix must be 10 for decimal floats.  */
386
      if ((result & CPP_N_DFLOAT) && radix != 10)
398
      if ((result & CPP_N_DFLOAT) && radix != 10)
387
        {
399
        {
388
          cpp_error (pfile, CPP_DL_ERROR,
400
          cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
389
                     "invalid suffix \"%.*s\" with hexadecimal floating constant",
401
			       "invalid suffix \"%.*s\" with hexadecimal floating constant",
390
                     (int) (limit - str), str);
402
			       (int) (limit - str), str);
391
          return CPP_N_INVALID;
403
          return CPP_N_INVALID;
392
        }
404
        }
393
405
394
      if ((result & (CPP_N_FRACT | CPP_N_ACCUM)) && CPP_PEDANTIC (pfile))
406
      if ((result & (CPP_N_FRACT | CPP_N_ACCUM)) && CPP_PEDANTIC (pfile))
395
	cpp_error (pfile, CPP_DL_PEDWARN,
407
	cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
396
		   "fixed-point constants are a GCC extension");
408
			     "fixed-point constants are a GCC extension");
397
409
398
      if ((result & CPP_N_DFLOAT) && CPP_PEDANTIC (pfile))
410
      if ((result & CPP_N_DFLOAT) && CPP_PEDANTIC (pfile))
399
	cpp_error (pfile, CPP_DL_PEDWARN,
411
	cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
400
		   "decimal float constants are a GCC extension");
412
			     "decimal float constants are a GCC extension");
401
413
402
      result |= CPP_N_FLOATING;
414
      result |= CPP_N_FLOATING;
403
    }
415
    }
Lines 406-414 cpp_classify_number (cpp_reader *pfile, const cpp_token *token) Link Here
406
      result = interpret_int_suffix (str, limit - str);
418
      result = interpret_int_suffix (str, limit - str);
407
      if (result == 0)
419
      if (result == 0)
408
	{
420
	{
409
	  cpp_error (pfile, CPP_DL_ERROR,
421
	  cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
410
		     "invalid suffix \"%.*s\" on integer constant",
422
			       "invalid suffix \"%.*s\" on integer constant",
411
		     (int) (limit - str), str);
423
			       (int) (limit - str), str);
412
	  return CPP_N_INVALID;
424
	  return CPP_N_INVALID;
413
	}
425
	}
414
426
Lines 421-429 cpp_classify_number (cpp_reader *pfile, const cpp_token *token) Link Here
421
		       && CPP_OPTION (pfile, cpp_warn_long_long);
433
		       && CPP_OPTION (pfile, cpp_warn_long_long);
422
434
423
	  if (u_or_i || large)
435
	  if (u_or_i || large)
424
	    cpp_warning (pfile, large ? CPP_W_LONG_LONG : CPP_W_TRADITIONAL,
436
	    cpp_warning_with_line (pfile, large ? CPP_W_LONG_LONG : CPP_W_TRADITIONAL,
425
		         "traditional C rejects the \"%.*s\" suffix",
437
				   virtual_location, 0,
426
		         (int) (limit - str), str);
438
				   "traditional C rejects the \"%.*s\" suffix",
439
				   (int) (limit - str), str);
427
	}
440
	}
428
441
429
      if ((result & CPP_N_WIDTH) == CPP_N_LARGE
442
      if ((result & CPP_N_WIDTH) == CPP_N_LARGE
Lines 434-442 cpp_classify_number (cpp_reader *pfile, const cpp_token *token) Link Here
434
		                : N_("use of C99 long long integer constant");
447
		                : N_("use of C99 long long integer constant");
435
448
436
	  if (CPP_OPTION (pfile, c99))
449
	  if (CPP_OPTION (pfile, c99))
437
            cpp_warning (pfile, CPP_W_LONG_LONG, message);
450
            cpp_warning_with_line (pfile, CPP_W_LONG_LONG, virtual_location,
451
				   0, message);
438
          else
452
          else
439
            cpp_pedwarning (pfile, CPP_W_LONG_LONG, message);
453
            cpp_pedwarning_with_line (pfile, CPP_W_LONG_LONG,
454
				      virtual_location, 0, message);
440
        }
455
        }
441
456
442
      result |= CPP_N_INTEGER;
457
      result |= CPP_N_INTEGER;
Lines 444-454 cpp_classify_number (cpp_reader *pfile, const cpp_token *token) Link Here
444
459
445
 syntax_ok:
460
 syntax_ok:
446
  if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
461
  if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
447
    cpp_error (pfile, CPP_DL_PEDWARN,
462
    cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
448
	       "imaginary constants are a GCC extension");
463
			 "imaginary constants are a GCC extension");
449
  if (radix == 2 && CPP_PEDANTIC (pfile))
464
  if (radix == 2 && CPP_PEDANTIC (pfile))
450
    cpp_error (pfile, CPP_DL_PEDWARN,
465
    cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
451
	       "binary constants are a GCC extension");
466
			 "binary constants are a GCC extension");
452
467
453
  if (radix == 10)
468
  if (radix == 10)
454
    result |= CPP_N_DECIMAL;
469
    result |= CPP_N_DECIMAL;
Lines 731-737 parse_defined (cpp_reader *pfile) Link Here
731
   number or character constant, or the result of the "defined" or "#"
746
   number or character constant, or the result of the "defined" or "#"
732
   operators).  */
747
   operators).  */
733
static cpp_num
748
static cpp_num
734
eval_token (cpp_reader *pfile, const cpp_token *token)
749
eval_token (cpp_reader *pfile, const cpp_token *token,
750
	    source_location virtual_location)
735
{
751
{
736
  cpp_num result;
752
  cpp_num result;
737
  unsigned int temp;
753
  unsigned int temp;
Lines 743-760 eval_token (cpp_reader *pfile, const cpp_token *token) Link Here
743
  switch (token->type)
759
  switch (token->type)
744
    {
760
    {
745
    case CPP_NUMBER:
761
    case CPP_NUMBER:
746
      temp = cpp_classify_number (pfile, token);
762
      temp = cpp_classify_number (pfile, token, virtual_location);
747
      switch (temp & CPP_N_CATEGORY)
763
      switch (temp & CPP_N_CATEGORY)
748
	{
764
	{
749
	case CPP_N_FLOATING:
765
	case CPP_N_FLOATING:
750
	  cpp_error (pfile, CPP_DL_ERROR,
766
	  cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
751
		     "floating constant in preprocessor expression");
767
			       "floating constant in preprocessor expression");
752
	  break;
768
	  break;
753
	case CPP_N_INTEGER:
769
	case CPP_N_INTEGER:
754
	  if (!(temp & CPP_N_IMAGINARY))
770
	  if (!(temp & CPP_N_IMAGINARY))
755
	    return cpp_interpret_integer (pfile, token, temp);
771
	    return cpp_interpret_integer (pfile, token, temp);
756
	  cpp_error (pfile, CPP_DL_ERROR,
772
	  cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
757
		     "imaginary number in preprocessor expression");
773
			       "imaginary number in preprocessor expression");
758
	  break;
774
	  break;
759
775
760
	case CPP_N_INVALID:
776
	case CPP_N_INVALID:
Lines 801-808 eval_token (cpp_reader *pfile, const cpp_token *token) Link Here
801
	  result.high = 0;
817
	  result.high = 0;
802
	  result.low = 0;
818
	  result.low = 0;
803
	  if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval)
819
	  if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval)
804
	    cpp_warning (pfile, CPP_W_UNDEF, "\"%s\" is not defined",
820
	    cpp_warning_with_line (pfile, CPP_W_UNDEF, virtual_location, 0,
805
		         NODE_NAME (token->val.node.node));
821
				   "\"%s\" is not defined",
822
				   NODE_NAME (token->val.node.node));
806
	}
823
	}
807
      break;
824
      break;
808
825
Lines 812-822 eval_token (cpp_reader *pfile, const cpp_token *token) Link Here
812
	  /* A pedantic warning takes precedence over a deprecated
829
	  /* A pedantic warning takes precedence over a deprecated
813
	     warning here.  */
830
	     warning here.  */
814
	  if (CPP_PEDANTIC (pfile))
831
	  if (CPP_PEDANTIC (pfile))
815
	    cpp_error (pfile, CPP_DL_PEDWARN,
832
	    cpp_error_with_line (pfile, CPP_DL_PEDWARN,
816
		       "assertions are a GCC extension");
833
				 virtual_location, 0,
834
				 "assertions are a GCC extension");
817
	  else if (CPP_OPTION (pfile, cpp_warn_deprecated))
835
	  else if (CPP_OPTION (pfile, cpp_warn_deprecated))
818
	    cpp_warning (pfile, CPP_W_DEPRECATED,
836
	    cpp_warning_with_line (pfile, CPP_W_DEPRECATED, virtual_location, 0,
819
		         "assertions are a deprecated extension");
837
				   "assertions are a deprecated extension");
820
	}
838
	}
821
      _cpp_test_assertion (pfile, &temp);
839
      _cpp_test_assertion (pfile, &temp);
822
      result.high = 0;
840
      result.high = 0;
Lines 918-923 _cpp_parse_expr (cpp_reader *pfile, bool is_if) Link Here
918
  struct op *top = pfile->op_stack;
936
  struct op *top = pfile->op_stack;
919
  unsigned int lex_count;
937
  unsigned int lex_count;
920
  bool saw_leading_not, want_value = true;
938
  bool saw_leading_not, want_value = true;
939
  source_location virtual_location = 0,
940
    prev_virtual_location = _cpp_get_prev_token_spelling_loc (pfile);
921
941
922
  pfile->state.skip_eval = 0;
942
  pfile->state.skip_eval = 0;
923
943
Lines 934-942 _cpp_parse_expr (cpp_reader *pfile, bool is_if) Link Here
934
      struct op op;
954
      struct op op;
935
955
936
      lex_count++;
956
      lex_count++;
937
      op.token = cpp_get_token (pfile);
957
958
      if (virtual_location)
959
	prev_virtual_location = virtual_location;
960
      op.token = cpp_get_token_with_location (pfile, &virtual_location);
938
      op.op = op.token->type;
961
      op.op = op.token->type;
939
      op.loc = op.token->src_loc;
962
      op.loc = virtual_location;
940
963
941
      switch (op.op)
964
      switch (op.op)
942
	{
965
	{
Lines 949-958 _cpp_parse_expr (cpp_reader *pfile, bool is_if) Link Here
949
	case CPP_NAME:
972
	case CPP_NAME:
950
	case CPP_HASH:
973
	case CPP_HASH:
951
	  if (!want_value)
974
	  if (!want_value)
952
	    SYNTAX_ERROR2 ("missing binary operator before token \"%s\"",
975
	    SYNTAX_ERROR2_AT (prev_virtual_location,
953
			   cpp_token_as_text (pfile, op.token));
976
			      "missing binary operator before token \"%s\"",
977
			      cpp_token_as_text (pfile, op.token));
954
	  want_value = false;
978
	  want_value = false;
955
	  top->value = eval_token (pfile, op.token);
979
	  top->value = eval_token (pfile, op.token, virtual_location);
956
	  continue;
980
	  continue;
957
981
958
	case CPP_NOT:
982
	case CPP_NOT:
Lines 969-976 _cpp_parse_expr (cpp_reader *pfile, bool is_if) Link Here
969
993
970
	default:
994
	default:
971
	  if ((int) op.op <= (int) CPP_EQ || (int) op.op >= (int) CPP_PLUS_EQ)
995
	  if ((int) op.op <= (int) CPP_EQ || (int) op.op >= (int) CPP_PLUS_EQ)
972
	    SYNTAX_ERROR2 ("token \"%s\" is not valid in preprocessor expressions",
996
	    SYNTAX_ERROR2_AT (op.loc,
973
			   cpp_token_as_text (pfile, op.token));
997
			      "token \"%s\" is not valid in preprocessor expressions",
998
			      cpp_token_as_text (pfile, op.token));
974
	  break;
999
	  break;
975
	}
1000
	}
976
1001
Lines 978-1004 _cpp_parse_expr (cpp_reader *pfile, bool is_if) Link Here
978
      if (optab[op.op].flags & NO_L_OPERAND)
1003
      if (optab[op.op].flags & NO_L_OPERAND)
979
	{
1004
	{
980
	  if (!want_value)
1005
	  if (!want_value)
981
	    SYNTAX_ERROR2 ("missing binary operator before token \"%s\"",
1006
	    SYNTAX_ERROR2_AT (prev_virtual_location,
982
			   cpp_token_as_text (pfile, op.token));
1007
			      "missing binary operator before token \"%s\"",
1008
			      cpp_token_as_text (pfile, op.token));
983
	}
1009
	}
984
      else if (want_value)
1010
      else if (want_value)
985
	{
1011
	{
986
	  /* We want a number (or expression) and haven't got one.
1012
	  /* We want a number (or expression) and haven't got one.
987
	     Try to emit a specific diagnostic.  */
1013
	     Try to emit a specific diagnostic.  */
988
	  if (op.op == CPP_CLOSE_PAREN && top->op == CPP_OPEN_PAREN)
1014
	  if (op.op == CPP_CLOSE_PAREN && top->op == CPP_OPEN_PAREN)
989
	    SYNTAX_ERROR ("missing expression between '(' and ')'");
1015
	    SYNTAX_ERROR_AT (op.loc,
1016
			     "missing expression between '(' and ')'");
990
1017
991
	  if (op.op == CPP_EOF && top->op == CPP_EOF)
1018
	  if (op.op == CPP_EOF && top->op == CPP_EOF)
992
 	    SYNTAX_ERROR2 ("%s with no expression", is_if ? "#if" : "#elif");
1019
 	    SYNTAX_ERROR2_AT (op.loc,
1020
			      "%s with no expression", is_if ? "#if" : "#elif");
993
1021
994
 	  if (top->op != CPP_EOF && top->op != CPP_OPEN_PAREN)
1022
 	  if (top->op != CPP_EOF && top->op != CPP_OPEN_PAREN)
995
 	    SYNTAX_ERROR2 ("operator '%s' has no right operand",
1023
 	    SYNTAX_ERROR2_AT (op.loc,
996
 			   cpp_token_as_text (pfile, top->token));
1024
			      "operator '%s' has no right operand",
1025
			      cpp_token_as_text (pfile, top->token));
997
	  else if (op.op == CPP_CLOSE_PAREN || op.op == CPP_EOF)
1026
	  else if (op.op == CPP_CLOSE_PAREN || op.op == CPP_EOF)
998
	    /* Complain about missing paren during reduction.  */;
1027
	    /* Complain about missing paren during reduction.  */;
999
	  else
1028
	  else
1000
	    SYNTAX_ERROR2 ("operator '%s' has no left operand",
1029
	    SYNTAX_ERROR2_AT (op.loc,
1001
			   cpp_token_as_text (pfile, op.token));
1030
			      "operator '%s' has no left operand",
1031
			      cpp_token_as_text (pfile, op.token));
1002
	}
1032
	}
1003
1033
1004
      top = reduce (pfile, top, op.op);
1034
      top = reduce (pfile, top, op.op);
Lines 1023-1029 _cpp_parse_expr (cpp_reader *pfile, bool is_if) Link Here
1023
	  break;
1053
	  break;
1024
	case CPP_COLON:
1054
	case CPP_COLON:
1025
	  if (top->op != CPP_QUERY)
1055
	  if (top->op != CPP_QUERY)
1026
	    SYNTAX_ERROR (" ':' without preceding '?'");
1056
	    SYNTAX_ERROR_AT (op.loc,
1057
			     " ':' without preceding '?'");
1027
	  if (!num_zerop (top[-1].value)) /* Was '?' condition true?  */
1058
	  if (!num_zerop (top[-1].value)) /* Was '?' condition true?  */
1028
	    pfile->state.skip_eval++;
1059
	    pfile->state.skip_eval++;
1029
	  else
1060
	  else
Lines 1040-1046 _cpp_parse_expr (cpp_reader *pfile, bool is_if) Link Here
1040
1071
1041
      top->op = op.op;
1072
      top->op = op.op;
1042
      top->token = op.token;
1073
      top->token = op.token;
1043
      top->loc = op.token->src_loc;
1074
      top->loc = op.loc;
1044
    }
1075
    }
1045
1076
1046
  /* The controlling macro expression is only valid if we called lex 3
1077
  /* The controlling macro expression is only valid if we called lex 3
Lines 1051-1058 _cpp_parse_expr (cpp_reader *pfile, bool is_if) Link Here
1051
1082
1052
  if (top != pfile->op_stack)
1083
  if (top != pfile->op_stack)
1053
    {
1084
    {
1054
      cpp_error (pfile, CPP_DL_ICE, "unbalanced stack in %s",
1085
      cpp_error_with_line (pfile, CPP_DL_ICE, top->loc, 0,
1055
		 is_if ? "#if" : "#elif");
1086
			   "unbalanced stack in %s",
1087
			   is_if ? "#if" : "#elif");
1056
    syntax_error:
1088
    syntax_error:
1057
      return false;  /* Return false on syntax error.  */
1089
      return false;  /* Return false on syntax error.  */
1058
    }
1090
    }
(-)a/libcpp/include/cpplib.h (-1 / +2 lines)
Lines 827-833 struct cpp_num Link Here
827
827
828
/* Classify a CPP_NUMBER token.  The return value is a combination of
828
/* Classify a CPP_NUMBER token.  The return value is a combination of
829
   the flags from the above sets.  */
829
   the flags from the above sets.  */
830
extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
830
extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *,
831
				     source_location);
831
832
832
/* Evaluate a token classified as category CPP_N_INTEGER.  */
833
/* Evaluate a token classified as category CPP_N_INTEGER.  */
833
extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
834
extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
(-)a/libcpp/internal.h (+1 lines)
Lines 640-645 extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *); Link Here
640
extern void _cpp_init_tokenrun (tokenrun *, unsigned int);
640
extern void _cpp_init_tokenrun (tokenrun *, unsigned int);
641
extern cpp_hashnode *_cpp_lex_identifier (cpp_reader *, const char *);
641
extern cpp_hashnode *_cpp_lex_identifier (cpp_reader *, const char *);
642
extern int _cpp_remaining_tokens_num_in_context (cpp_reader *);
642
extern int _cpp_remaining_tokens_num_in_context (cpp_reader *);
643
extern source_location _cpp_get_prev_token_spelling_loc (cpp_reader *);
643
644
644
/* In init.c.  */
645
/* In init.c.  */
645
extern void _cpp_maybe_push_include_file (cpp_reader *);
646
extern void _cpp_maybe_push_include_file (cpp_reader *);
(-)a/libcpp/lex.c (+31 lines)
Lines 2905-2907 cpp_token_val_index (cpp_token *tok) Link Here
2905
      return CPP_TOKEN_FLD_NONE;
2905
      return CPP_TOKEN_FLD_NONE;
2906
    }
2906
    }
2907
}
2907
}
2908
2909
/* Return the location of the previous token in the token stream.  */
2910
2911
source_location
2912
_cpp_get_prev_token_spelling_loc (cpp_reader *pfile)
2913
{
2914
  source_location spelling_loc;
2915
2916
  if (CPP_OPTION (pfile, traditional))
2917
    {
2918
      if (pfile->state.in_directive)
2919
	spelling_loc = pfile->directive_line;
2920
      else
2921
	spelling_loc = LINEMAPS_ORDINARY_HIGHEST_LINE (pfile->line_table);
2922
    }
2923
  /* We don't want to refer to a token before the beginning of the
2924
     current run -- that is invalid.  */
2925
  else if (pfile->cur_token == pfile->cur_run->base)
2926
    {
2927
      if (pfile->cur_run->prev != NULL)
2928
	spelling_loc = pfile->cur_run->prev->limit->src_loc;
2929
      else
2930
	spelling_loc = 0;
2931
    }
2932
  else
2933
    {
2934
      spelling_loc = pfile->cur_token[-1].src_loc;
2935
    }
2936
2937
  return spelling_loc;
2938
}
(-)a/libcpp/macro.c (-1 / +18 lines)
Lines 2069-2074 consume_next_token_from_context (cpp_reader *pfile, Link Here
2069
    abort ();
2069
    abort ();
2070
}
2070
}
2071
2071
2072
/* In the traditionnal mode of the preprocessor, if we are currently
2073
   in a directive, the location of a token must be the location of the
2074
   start of the directive line. This function returns the proper
2075
   location if we are in the traditionnal mode, and just returns
2076
   LOCATION otherwise.   */
2077
2078
static inline source_location
2079
maybe_adjust_loc_for_trad_cpp (cpp_reader *pfile, source_location location)
2080
{
2081
  if (CPP_OPTION (pfile, traditional))
2082
    {
2083
      if (pfile->state.in_directive)
2084
	return pfile->directive_line;
2085
    }
2086
  return location;
2087
}
2088
2072
/* Routine to get a token as well as its location.
2089
/* Routine to get a token as well as its location.
2073
2090
2074
   Macro expansions and directives are transparently handled,
2091
   Macro expansions and directives are transparently handled,
Lines 2302-2307 cpp_get_token_with_location (cpp_reader *pfile, source_location *loc) Link Here
2302
  else
2319
  else
2303
    *loc = result->src_loc;
2320
    *loc = result->src_loc;
2304
2321
2322
  *loc = maybe_adjust_loc_for_trad_cpp (pfile, *loc);
2305
  return result;
2323
  return result;
2306
}
2324
}
2307
2325
2308
- 

Return to bug 7263