re PR preprocessor/34695 (Preprocessor warning->error conversion from -Werror is silent)

PR preprocessor/34695

gcc:
	* Makefile.in (c-opts.o): Depend on c-tree.h.
	* c-common.c: Move down include of diagnostic.h.
	(done_lexing, c_cpp_error): New.
	* c-common.h (done_lexing): Declare.
	* c-decl.c (c_write_global_declarations): Don't check cpp_errors
	(parse_in).
	* c-opts.c: Include c-tree.h.
	(c_common_init_options): Set preprocessor error callback.
	(c_common_handle_option): Do not set preprocessor
	inhibit_warnings, warnings_are_errors, warn_system_headers,
	pedantic_errors or inhibit_warnings flags.
	(c_common_post_options): Do not check cpp_errors (parse_in).
	(c_common_finish): Do not output dependencies if there were
	errors.  Do not check return value of cpp_finish.
	* c-ppoutput.c (pp_file_change): Set input_location.
	* c-tree.h (c_cpp_error): Declare.
	* diagnostic.c (diagnostic_set_info_translated): Also initialize
	override_column.
	(diagnostic_build_prefix): Check override_column.
	* diagnostic.h (diagnostic_info): Add override_column field.
	(diagnostic_override_column): Define.

gcc/cp:
	* cp-tree.h (cp_cpp_error): Remove.
	* error.c (cp_cpp_error): Remove.
	* parser.c (cp_lexer_new_main): Set done_lexing instead of
	client_diagnostic and error callback.

gcc/fortran:
	* cpp.c (cb_cpp_error): New.
	(gfc_cpp_post_options): Don't set cpp_option->inhibit_warnings.
	Don't check cpp_errors (cpp_in).
	(gfc_cpp_init_0): Set cb->error.

gcc/testsuite:
	* gcc.dg/builtin-redefine.c, gcc.dg/cpp/redef2.c,
	gcc.dg/cpp/redef3.c, gcc.dg/cpp/trad/redef2.c: Use dg-message
	instead of dg-warning for "previous definition" messages.
	* gcc.dg/cpp/Wvariadic-1.c, gcc.dg/cpp/Wvariadic-3.c: Expect
	"warnings being treated as errors" message.
	* gcc.dg/fltconst-1.c: Use -fshow-column.

libcpp:
	* makedepend.c: Remove.
	* Makefile.in (makedepend_OBJS, makedepend$(EXEEXT)): Remove.
	(all, clean, TAGS_SOURCES, include): Remove makedepend handling.
	* directives.c (cpp_errors): Remove.
	* errors.c (print_location, _cpp_begin_message, v_message):
	Remove.
	(cpp_error, cpp_error_with_line): Always use error callback.
	(cpp_error, cpp_error_with_line, cpp_errno): Return bool.
	* include/cpplib.h (cpp_options): Remove pedantic_errors,
	inhibit_warnings, warn_system_headers, inhibit_errors,
	warnings_are_errors, client_diagnostic.
	(cpp_callbacks): Add extra arguments to error callback; make it
	return bool.
	(cpp_finish): Return void.
	(cpp_destroy): Remove inaccurate comment about return value.
	(cpp_errors, CPP_DL_EXTRACT, CPP_DL_WARNING_P): Remove.
	(CPP_DL_NOTE): Define.
	* include/line-map.h (linemap_print_containing_files): Remove.
	* init.c (cpp_finish): Do not check for or return number of
	errors.
	* internal.h (cpp_reader): Remove errors field.
	* line-map.c (linemap_print_containing_files): Remove.
	* macro.c (_cpp_create_definition): Use CPP_DL_NOTE for message
	about previous definition.  Only emit it if previous diagnostic
	was emitted.

From-SVN: r145263
This commit is contained in:
Joseph Myers 2009-03-29 23:56:07 +01:00 committed by Joseph Myers
parent ba20e30910
commit 148e4216a4
35 changed files with 321 additions and 556 deletions

View file

@ -1,6 +1,6 @@
/* Default error handlers for CPP Library.
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, 1999, 2000,
2001, 2002, 2004, 2008 Free Software Foundation, Inc.
2001, 2002, 2004, 2008, 2009 Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@ -28,171 +28,69 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "cpplib.h"
#include "internal.h"
static void print_location (cpp_reader *, source_location, unsigned int);
/* Print the logical file location (LINE, COL) in preparation for a
diagnostic. Outputs the #include chain if it has changed. A line
of zero suppresses the include stack, and outputs the program name
instead. */
static void
print_location (cpp_reader *pfile, source_location line, unsigned int col)
{
if (line == 0)
fprintf (stderr, "%s: ", progname);
else
{
const struct line_map *map;
linenum_type lin;
map = linemap_lookup (pfile->line_table, line);
linemap_print_containing_files (pfile->line_table, map);
lin = SOURCE_LINE (map, line);
if (col == 0)
{
col = SOURCE_COLUMN (map, line);
if (col == 0)
col = 1;
}
if (lin == 0)
fprintf (stderr, "%s:", map->to_file);
else if (CPP_OPTION (pfile, show_column) == 0)
fprintf (stderr, "%s:%u:", map->to_file, lin);
else
fprintf (stderr, "%s:%u:%u:", map->to_file, lin, col);
fputc (' ', stderr);
}
}
/* Set up for a diagnostic: print the file and line, bump the error
counter, etc. SRC_LOC is the logical line number; zero means to print
at the location of the previously lexed token, which tends to be
the correct place by default. The column number can be specified either
using COLUMN or (if COLUMN==0) extracting SOURCE_COLUMN from SRC_LOC.
(This may seem redundant, but is useful when pre-scanning (cleaning) a line,
when we haven't yet verified whether the current line_map has a
big enough max_column_hint.)
Returns 0 if the error has been suppressed. */
static int
_cpp_begin_message (cpp_reader *pfile, int code,
source_location src_loc, unsigned int column)
{
int level = CPP_DL_EXTRACT (code);
switch (level)
{
case CPP_DL_WARNING:
case CPP_DL_PEDWARN:
if (cpp_in_system_header (pfile)
&& ! CPP_OPTION (pfile, warn_system_headers))
return 0;
/* Fall through. */
case CPP_DL_WARNING_SYSHDR:
if (CPP_OPTION (pfile, warnings_are_errors)
|| (level == CPP_DL_PEDWARN && CPP_OPTION (pfile, pedantic_errors)))
{
if (CPP_OPTION (pfile, inhibit_errors))
return 0;
level = CPP_DL_ERROR;
pfile->errors++;
}
else if (CPP_OPTION (pfile, inhibit_warnings))
return 0;
break;
case CPP_DL_ERROR:
if (CPP_OPTION (pfile, inhibit_errors))
return 0;
/* ICEs cannot be inhibited. */
case CPP_DL_ICE:
pfile->errors++;
break;
}
print_location (pfile, src_loc, column);
if (CPP_DL_WARNING_P (level))
fputs (_("warning: "), stderr);
else if (level == CPP_DL_ICE)
fputs (_("internal error: "), stderr);
else
fputs (_("error: "), stderr);
return 1;
}
/* Don't remove the blank before do, as otherwise the exgettext
script will mistake this as a function definition */
#define v_message(msgid, ap) \
do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
/* Exported interface. */
/* Print an error at the location of the previously lexed token. */
void
bool
cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
{
source_location src_loc;
va_list ap;
bool ret;
va_start (ap, msgid);
if (CPP_OPTION (pfile, client_diagnostic))
pfile->cb.error (pfile, level, _(msgid), &ap);
if (CPP_OPTION (pfile, traditional))
{
if (pfile->state.in_directive)
src_loc = pfile->directive_line;
else
src_loc = pfile->line_table->highest_line;
}
/* We don't want to refer to a token before the beginning of the
current run -- that is invalid. */
else if (pfile->cur_token == pfile->cur_run->base)
{
if (pfile->cur_run->prev != NULL)
src_loc = pfile->cur_run->prev->limit->src_loc;
else
src_loc = 0;
}
else
{
if (CPP_OPTION (pfile, traditional))
{
if (pfile->state.in_directive)
src_loc = pfile->directive_line;
else
src_loc = pfile->line_table->highest_line;
}
/* We don't want to refer to a token before the beginning of the
current run -- that is invalid. */
else if (pfile->cur_token == pfile->cur_run->base)
{
if (pfile->cur_run->prev != NULL)
src_loc = pfile->cur_run->prev->limit->src_loc;
else
src_loc = 0;
}
else
{
src_loc = pfile->cur_token[-1].src_loc;
}
if (_cpp_begin_message (pfile, level, src_loc, 0))
v_message (msgid, ap);
src_loc = pfile->cur_token[-1].src_loc;
}
if (!pfile->cb.error)
abort ();
ret = pfile->cb.error (pfile, level, src_loc, 0, _(msgid), &ap);
va_end (ap);
return ret;
}
/* Print an error at a specific location. */
void
bool
cpp_error_with_line (cpp_reader *pfile, int level,
source_location src_loc, unsigned int column,
const char *msgid, ...)
{
va_list ap;
bool ret;
va_start (ap, msgid);
if (_cpp_begin_message (pfile, level, src_loc, column))
v_message (msgid, ap);
if (!pfile->cb.error)
abort ();
ret = pfile->cb.error (pfile, level, src_loc, column, _(msgid), &ap);
va_end (ap);
return ret;
}
void
bool
cpp_errno (cpp_reader *pfile, int level, const char *msgid)
{
if (msgid[0] == '\0')
msgid = _("stdout");
cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
return cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
}