+2008-05-21 Tom Tromey <tromey@redhat.com>
+
+ PR preprocessor/27777:
+ * gcc.dg/cpp/pr27777.c: New file.
+
2008-05-21 Jakub Jelinek <jakub@redhat.com>
PR c++/36023
--- /dev/null
+/* PR preprocessor/27777 */
+/* { dg-do preprocess } */
+/* { dg-options { -trigraphs -Wall } } */
+
+#error "BUG??!"
+
+/* { dg-error "BUG" "" { target *-*-* } 5 } */
+/* { dg-warning "trigraph" "" { target *-*-* } 5 } */
+2008-05-21 Tom Tromey <tromey@redhat.com>
+
+ PR preprocessor/27777:
+ * lex.c (cpp_output_line_to_string): New function.
+ * internal.h (_cpp_begin_message): Don't declare.
+ * errors.c (_cpp_begin_message): Now static.
+ * include/cpplib.h (cpp_output_line_to_string): Declare.
+ * directives.c (do_diagnostic): Rewrote. Use
+ cpp_output_line_to_string. Don't use _cpp_begin_message.
+
2008-05-21 Tom Tromey <tromey@redhat.com>
* include/symtab.h (HT_ALLOCED): Remove.
static void
do_diagnostic (cpp_reader *pfile, int code, int print_dir)
{
- if (_cpp_begin_message (pfile, code, pfile->cur_token[-1].src_loc, 0))
- {
- if (print_dir)
- fprintf (stderr, "#%s ", pfile->directive->name);
- pfile->state.prevent_expansion++;
- cpp_output_line (pfile, stderr);
- pfile->state.prevent_expansion--;
- }
+ const unsigned char *dir_name;
+ unsigned char *line;
+ source_location src_loc = pfile->cur_token[-1].src_loc;
+
+ if (print_dir)
+ dir_name = pfile->directive->name;
+ else
+ dir_name = NULL;
+ pfile->state.prevent_expansion++;
+ line = cpp_output_line_to_string (pfile, dir_name);
+ pfile->state.prevent_expansion--;
+
+ cpp_error_with_line (pfile, code, src_loc, 0, "%s", line);
+ free (line);
}
static void
big enough max_column_hint.)
Returns 0 if the error has been suppressed. */
-int
+static int
_cpp_begin_message (cpp_reader *pfile, int code,
source_location src_loc, unsigned int column)
{
/* In lex.c */
extern int cpp_ideq (const cpp_token *, const char *);
extern void cpp_output_line (cpp_reader *, FILE *);
+extern unsigned char *cpp_output_line_to_string (cpp_reader *,
+ const unsigned char *);
extern void cpp_output_token (const cpp_token *, FILE *);
extern const char *cpp_type2name (enum cpp_ttype);
/* Returns the value of an escape sequence, truncated to the correct
return pfile->line_table->depth == 1;
}
-/* In errors.c */
-extern int _cpp_begin_message (cpp_reader *, int,
- source_location, unsigned int);
-
/* In macro.c */
extern void _cpp_free_definition (cpp_hashnode *);
extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);
/* CPP Library - lexical analysis.
- Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
putc ('\n', fp);
}
+/* Return a string representation of all the remaining tokens on the
+ current line. The result is allocated using xmalloc and must be
+ freed by the caller. */
+unsigned char *
+cpp_output_line_to_string (cpp_reader *pfile, const unsigned char *dir_name)
+{
+ const cpp_token *token;
+ unsigned int out = dir_name ? ustrlen (dir_name) : 0;
+ unsigned int alloced = 120 + out;
+ unsigned char *result = (unsigned char *) xmalloc (alloced);
+
+ /* If DIR_NAME is empty, there are no initial contents. */
+ if (dir_name)
+ {
+ sprintf ((char *) result, "#%s ", dir_name);
+ out += 2;
+ }
+
+ token = cpp_get_token (pfile);
+ while (token->type != CPP_EOF)
+ {
+ unsigned char *last;
+ /* Include room for a possible space and the terminating nul. */
+ unsigned int len = cpp_token_len (token) + 2;
+
+ if (out + len > alloced)
+ {
+ alloced *= 2;
+ if (out + len > alloced)
+ alloced = out + len;
+ result = (unsigned char *) xrealloc (result, alloced);
+ }
+
+ last = cpp_spell_token (pfile, token, &result[out], 0);
+ out = last - result;
+
+ token = cpp_get_token (pfile);
+ if (token->flags & PREV_WHITE)
+ result[out++] = ' ';
+ }
+
+ result[out] = '\0';
+ return result;
+}
+
/* Memory buffers. Changing these three constants can have a dramatic
effect on performance. The values here are reasonable defaults,
but might be tuned. If you adjust them, be sure to test across a