Commit 87cf0651 by Simon Baldwin

diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.

	* diagnostic.h (diagnostic_override_option_index): New macro to
	set a diagnostic's option_index.
	* c-tree.h (c_cpp_error): Add warning reason argument.
	* opts.c (_warning_as_error_callback): New.
	(register_warning_as_error_callback): Store callback for
	warnings enabled via enable_warning_as_error.
	(enable_warning_as_error): Call callback, minor code tidy.
	* opts.h (register_warning_as_error_callback): Declare.
	* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
	response to -Werror=.
	(c_common_init_options): Register warning_as_error_callback in opts.c.
	* common.opt: Add -Wno-cpp option.
	* c-common.c (struct reason_option_codes_t): Map cpp warning
	reason codes to gcc option indexes.
	* (c_option_controlling_cpp_error): New function, lookup the gcc
	option index for a cpp warning reason code.
	* (c_cpp_error): Add warning reason argument, call
	c_option_controlling_cpp_error for diagnostic_override_option_index.
	* doc/invoke.texi: Document -Wno-cpp.

	* cpp.c (cb_cpp_error): Add warning reason argument, set a value
	for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.

	* directives.c (do_diagnostic): Add warning reason argument,
	call appropriate error reporting function for code.
	(directive_diagnostics): Call specific warning functions with
	warning reason where appropriate.
	(do_error, do_warning, do_pragma_dependency): Add warning reason
	argument to do_diagnostic calls.
	* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
	_cpp_create_definition): Call specific warning functions with
        warning reason where appropriate.
	* Makefile.in: Add new diagnostic functions to gettext translations.
	* include/cpplib.h (struct cpp_callbacks): Add warning reason code
	to error callback.
	(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
	CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
	(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
	CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
	CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
	CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
	CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
	CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
	CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
	warning reason codes.
	(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
	cpp_warning_with_line, cpp_pedwarning_with_line,
	cpp_warning_with_line_syshdr): New specific error reporting functions.
	* pch.c (cpp_valid_state): Call specific warning functions with
        warning reason where appropriate.
	* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
	diagnostic handlers.
	(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
	cpp_warning_with_line, cpp_pedwarning_with_line,
	cpp_warning_with_line_syshdr): New specific error reporting functions.
	* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
	specific warning functions with warning reason where appropriate.
	* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
	warn_about_normalization, lex_identifier_intern, lex_identifier,
	_cpp_lex_direct): Ditto.
	* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
	narrow_str_to_charconst): Ditto.

	* gcc.dg/cpp/warn-undef-2.c: New.
	* gcc.dg/cpp/warn-traditional-2.c: New.
	* gcc.dg/cpp/warn-comments-2.c: New.
	* gcc.dg/cpp/warning-directive-1.c: New.
	* gcc.dg/cpp/warn-long-long.c: New.
	* gcc.dg/cpp/warn-traditional.c: New.
	* gcc.dg/cpp/warn-variadic-2.c: New.
	* gcc.dg/cpp/warn-undef.c: New.
	* gcc.dg/cpp/warn-normalized-1.c: New.
	* gcc.dg/cpp/warning-directive-2.c: New.
	* gcc.dg/cpp/warn-long-long-2.c: New.
	* gcc.dg/cpp/warn-variadic.c: New.
	* gcc.dg/cpp/warn-normalized-2.c: New.
	* gcc.dg/cpp/warning-directive-3.c: New.
	* gcc.dg/cpp/warn-deprecated-2.c: New.
	* gcc.dg/cpp/warn-trigraphs-1.c: New.
	* gcc.dg/cpp/warn-multichar-2.c: New.
	* gcc.dg/cpp/warn-normalized-3.c: New.
	* gcc.dg/cpp/warning-directive-4.c: New.
	* gcc.dg/cpp/warn-unused-macros.c: New.
	* gcc.dg/cpp/warn-trigraphs-2.c: New.
	* gcc.dg/cpp/warn-cxx-compat-2.c: New.
	* gcc.dg/cpp/warn-cxx-compat.c: New.
	* gcc.dg/cpp/warn-redefined.c: New.
	* gcc.dg/cpp/warn-trigraphs-3.c: New.
	* gcc.dg/cpp/warn-unused-macros-2.c: New.
	* gcc.dg/cpp/warn-deprecated.c: New.
	* gcc.dg/cpp/warn-trigraphs-4.c: New.
	* gcc.dg/cpp/warn-redefined-2.c: New.
	* gcc.dg/cpp/warn-comments.c: New.
	* gcc.dg/cpp/warn-multichar.c: New.
	* g++.dg/cpp/warning-directive-1.C: New.
	* g++.dg/cpp/warning-directive-2.C: New.
	* g++.dg/cpp/warning-directive-3.C: New.
	* g++.dg/cpp/warning-directive-4.C: New.
	* gfortran.dg/warning-directive-1.F90: New.
	* gfortran.dg/warning-directive-3.F90: New.
	* gfortran.dg/warning-directive-2.F90: New.
	* gfortran.dg/warning-directive-4.F90: New.

From-SVN: r158079
parent 58e0f0d3
2010-04-07 Simon Baldwin <simonb@google.com>
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
2010-04-07 Richard Guenther <rguenther@suse.de> 2010-04-07 Richard Guenther <rguenther@suse.de>
* ipa-reference.c (mark_load): Use get_base_address. * ipa-reference.c (mark_load): Use get_base_address.
......
...@@ -8253,8 +8253,52 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type, ...@@ -8253,8 +8253,52 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
#undef catenate_messages #undef catenate_messages
} }
/* Mapping for cpp message reasons to the options that enable them. */
struct reason_option_codes_t
{
const int reason; /* cpplib message reason. */
const int option_code; /* gcc option that controls this message. */
};
static const struct reason_option_codes_t option_codes[] = {
{CPP_W_DEPRECATED, OPT_Wdeprecated},
{CPP_W_COMMENTS, OPT_Wcomments},
{CPP_W_TRIGRAPHS, OPT_Wtrigraphs},
{CPP_W_MULTICHAR, OPT_Wmultichar},
{CPP_W_TRADITIONAL, OPT_Wtraditional},
{CPP_W_LONG_LONG, OPT_Wlong_long},
{CPP_W_ENDIF_LABELS, OPT_Wendif_labels},
{CPP_W_VARIADIC_MACROS, OPT_Wvariadic_macros},
{CPP_W_BUILTIN_MACRO_REDEFINED, OPT_Wbuiltin_macro_redefined},
{CPP_W_UNDEF, OPT_Wundef},
{CPP_W_UNUSED_MACROS, OPT_Wunused_macros},
{CPP_W_CXX_OPERATOR_NAMES, OPT_Wc___compat},
{CPP_W_NORMALIZE, OPT_Wnormalized_},
{CPP_W_INVALID_PCH, OPT_Winvalid_pch},
{CPP_W_WARNING_DIRECTIVE, OPT_Wcpp},
{CPP_W_NONE, 0}
};
/* Return the gcc option code associated with the reason for a cpp
message, or 0 if none. */
static int
c_option_controlling_cpp_error (int reason)
{
const struct reason_option_codes_t *entry;
for (entry = option_codes; entry->reason != CPP_W_NONE; entry++)
{
if (entry->reason == reason)
return entry->option_code;
}
return 0;
}
/* Callback from cpp_error for PFILE to print diagnostics from the /* Callback from cpp_error for PFILE to print diagnostics from the
preprocessor. The diagnostic is of type LEVEL, at location preprocessor. The diagnostic is of type LEVEL, with REASON set
to the reason code if LEVEL is represents a warning, at location
LOCATION unless this is after lexing and the compiler's location LOCATION unless this is after lexing and the compiler's location
should be used instead, with column number possibly overridden by should be used instead, with column number possibly overridden by
COLUMN_OVERRIDE if not zero; MSG is the translated message and AP COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
...@@ -8262,7 +8306,7 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type, ...@@ -8262,7 +8306,7 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
otherwise. */ otherwise. */
bool bool
c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason,
location_t location, unsigned int column_override, location_t location, unsigned int column_override,
const char *msg, va_list *ap) const char *msg, va_list *ap)
{ {
...@@ -8309,6 +8353,8 @@ c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, ...@@ -8309,6 +8353,8 @@ c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level,
location, dlevel); location, dlevel);
if (column_override) if (column_override)
diagnostic_override_column (&diagnostic, column_override); diagnostic_override_column (&diagnostic, column_override);
diagnostic_override_option_index (&diagnostic,
c_option_controlling_cpp_error (reason));
ret = report_diagnostic (&diagnostic); ret = report_diagnostic (&diagnostic);
if (level == CPP_DL_WARNING_SYSHDR) if (level == CPP_DL_WARNING_SYSHDR)
warn_system_headers = save_warn_system_headers; warn_system_headers = save_warn_system_headers;
......
...@@ -196,6 +196,90 @@ defer_opt (enum opt_code code, const char *arg) ...@@ -196,6 +196,90 @@ defer_opt (enum opt_code code, const char *arg)
deferred_count++; deferred_count++;
} }
/* -Werror= may set a warning option to enable a warning that is emitted
by the preprocessor. Set any corresponding flag in cpp_opts. */
static void
warning_as_error_callback (int option_index)
{
switch (option_index)
{
default:
/* Ignore options not associated with the preprocessor. */
break;
case OPT_Wdeprecated:
cpp_opts->warn_deprecated = 1;
break;
case OPT_Wcomment:
case OPT_Wcomments:
cpp_opts->warn_comments = 1;
break;
case OPT_Wtrigraphs:
cpp_opts->warn_trigraphs = 1;
break;
case OPT_Wmultichar:
cpp_opts->warn_multichar = 1;
break;
case OPT_Wtraditional:
cpp_opts->warn_traditional = 1;
break;
case OPT_Wlong_long:
cpp_opts->warn_long_long = 1;
break;
case OPT_Wendif_labels:
cpp_opts->warn_endif_labels = 1;
break;
case OPT_Wvariadic_macros:
/* Set the local flag that is used later to update cpp_opts. */
warn_variadic_macros = 1;
break;
case OPT_Wbuiltin_macro_redefined:
cpp_opts->warn_builtin_macro_redefined = 1;
break;
case OPT_Wundef:
cpp_opts->warn_undef = 1;
break;
case OPT_Wunused_macros:
/* Set the local flag that is used later to update cpp_opts. */
warn_unused_macros = 1;
break;
case OPT_Wc___compat:
/* Add warnings in the same way as c_common_handle_option below. */
if (warn_enum_compare == -1)
warn_enum_compare = 1;
if (warn_jump_misses_init == -1)
warn_jump_misses_init = 1;
cpp_opts->warn_cxx_operator_names = 1;
break;
case OPT_Wnormalized_:
inform (input_location, "-Werror=normalized=: Set -Wnormalized=nfc");
cpp_opts->warn_normalize = normalized_C;
break;
case OPT_Winvalid_pch:
cpp_opts->warn_invalid_pch = 1;
break;
case OPT_Wcpp:
/* Handled by standard diagnostics using the option's associated
boolean variable. */
break;
}
}
/* Common initialization before parsing options. */ /* Common initialization before parsing options. */
unsigned int unsigned int
c_common_init_options (unsigned int argc, const char **argv) c_common_init_options (unsigned int argc, const char **argv)
...@@ -204,6 +288,9 @@ c_common_init_options (unsigned int argc, const char **argv) ...@@ -204,6 +288,9 @@ c_common_init_options (unsigned int argc, const char **argv)
unsigned int i, result; unsigned int i, result;
struct cpp_callbacks *cb; struct cpp_callbacks *cb;
/* Register callback for warnings enabled by -Werror=. */
register_warning_as_error_callback (warning_as_error_callback);
/* This is conditionalized only because that is the way the front /* This is conditionalized only because that is the way the front
ends used to do it. Maybe this should be unconditional? */ ends used to do it. Maybe this should be unconditional? */
if (c_dialect_cxx ()) if (c_dialect_cxx ())
......
...@@ -608,8 +608,8 @@ extern void c_write_global_declarations (void); ...@@ -608,8 +608,8 @@ extern void c_write_global_declarations (void);
extern void pedwarn_c90 (location_t, int opt, const char *, ...) ATTRIBUTE_GCC_CDIAG(3,4); extern void pedwarn_c90 (location_t, int opt, const char *, ...) ATTRIBUTE_GCC_CDIAG(3,4);
extern void pedwarn_c99 (location_t, int opt, const char *, ...) ATTRIBUTE_GCC_CDIAG(3,4); extern void pedwarn_c99 (location_t, int opt, const char *, ...) ATTRIBUTE_GCC_CDIAG(3,4);
extern bool c_cpp_error (cpp_reader *, int, location_t, unsigned int, extern bool c_cpp_error (cpp_reader *, int, int, location_t, unsigned int,
const char *, va_list *) const char *, va_list *)
ATTRIBUTE_GCC_CDIAG(5,0); ATTRIBUTE_GCC_CDIAG(6,0);
#endif /* ! GCC_C_TREE_H */ #endif /* ! GCC_C_TREE_H */
...@@ -89,6 +89,10 @@ Wcast-align ...@@ -89,6 +89,10 @@ Wcast-align
Common Var(warn_cast_align) Warning Common Var(warn_cast_align) Warning
Warn about pointer casts which increase alignment Warn about pointer casts which increase alignment
Wcpp
Common Var(warn_cpp) Init(1) Warning
Warn when a #warning directive is encountered
Wdeprecated-declarations Wdeprecated-declarations
Common Var(warn_deprecated_decl) Init(1) Warning Common Var(warn_deprecated_decl) Init(1) Warning
Warn about uses of __attribute__((deprecated)) declarations Warn about uses of __attribute__((deprecated)) declarations
......
...@@ -199,6 +199,11 @@ extern diagnostic_context *global_dc; ...@@ -199,6 +199,11 @@ extern diagnostic_context *global_dc;
diagnostic. */ diagnostic. */
#define diagnostic_override_column(DI, COL) (DI)->override_column = (COL) #define diagnostic_override_column(DI, COL) (DI)->override_column = (COL)
/* Override the option index to be used for reporting a
diagnostic. */
#define diagnostic_override_option_index(DI, OPTIDX) \
((DI)->option_index = (OPTIDX))
/* Diagnostic related functions. */ /* Diagnostic related functions. */
extern void diagnostic_initialize (diagnostic_context *); extern void diagnostic_initialize (diagnostic_context *);
extern void diagnostic_report_current_module (diagnostic_context *); extern void diagnostic_report_current_module (diagnostic_context *);
......
...@@ -232,7 +232,7 @@ Objective-C and Objective-C++ Dialects}. ...@@ -232,7 +232,7 @@ Objective-C and Objective-C++ Dialects}.
-Wno-attributes -Wno-builtin-macro-redefined @gol -Wno-attributes -Wno-builtin-macro-redefined @gol
-Wc++-compat -Wc++0x-compat -Wcast-align -Wcast-qual @gol -Wc++-compat -Wc++0x-compat -Wcast-align -Wcast-qual @gol
-Wchar-subscripts -Wclobbered -Wcomment @gol -Wchar-subscripts -Wclobbered -Wcomment @gol
-Wconversion -Wcoverage-mismatch -Wno-deprecated @gol -Wconversion -Wcoverage-mismatch -Wcpp -Wno-deprecated @gol
-Wno-deprecated-declarations -Wdisabled-optimization @gol -Wno-deprecated-declarations -Wdisabled-optimization @gol
-Wno-div-by-zero -Wempty-body -Wenum-compare -Wno-endif-labels @gol -Wno-div-by-zero -Wempty-body -Wenum-compare -Wno-endif-labels @gol
-Werror -Werror=* @gol -Werror -Werror=* @gol
...@@ -2973,6 +2973,11 @@ Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*} ...@@ -2973,6 +2973,11 @@ Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
comment, or whenever a Backslash-Newline appears in a @samp{//} comment. comment, or whenever a Backslash-Newline appears in a @samp{//} comment.
This warning is enabled by @option{-Wall}. This warning is enabled by @option{-Wall}.
@item -Wno-cpp \
@r{(C, Objective-C, C++, Objective-C++ and Fortran only)}
Suppress warning messages emitted by @code{#warning} directives.
@item -Wformat @item -Wformat
@opindex Wformat @opindex Wformat
@opindex Wno-format @opindex Wno-format
......
2010-04-07 Simon Baldwin <simonb@google.com>
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
2010-04-07 Richard Guenther <rguenther@suse.de> 2010-04-07 Richard Guenther <rguenther@suse.de>
* options.c (gfc_init_options): Do not set. * options.c (gfc_init_options): Do not set.
......
...@@ -137,9 +137,9 @@ static void cb_include (cpp_reader *, source_location, const unsigned char *, ...@@ -137,9 +137,9 @@ static void cb_include (cpp_reader *, source_location, const unsigned char *,
static void cb_ident (cpp_reader *, source_location, const cpp_string *); static void cb_ident (cpp_reader *, source_location, const cpp_string *);
static void cb_used_define (cpp_reader *, source_location, cpp_hashnode *); static void cb_used_define (cpp_reader *, source_location, cpp_hashnode *);
static void cb_used_undef (cpp_reader *, source_location, cpp_hashnode *); static void cb_used_undef (cpp_reader *, source_location, cpp_hashnode *);
static bool cb_cpp_error (cpp_reader *, int, location_t, unsigned int, static bool cb_cpp_error (cpp_reader *, int, int, location_t, unsigned int,
const char *, va_list *) const char *, va_list *)
ATTRIBUTE_GCC_DIAG(5,0); ATTRIBUTE_GCC_DIAG(6,0);
void pp_dir_change (cpp_reader *, const char *); void pp_dir_change (cpp_reader *, const char *);
static int dump_macro (cpp_reader *, cpp_hashnode *, void *); static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
...@@ -962,13 +962,14 @@ cb_used_define (cpp_reader *pfile, source_location line ATTRIBUTE_UNUSED, ...@@ -962,13 +962,14 @@ cb_used_define (cpp_reader *pfile, source_location line ATTRIBUTE_UNUSED,
} }
/* Callback from cpp_error for PFILE to print diagnostics from the /* Callback from cpp_error for PFILE to print diagnostics from the
preprocessor. The diagnostic is of type LEVEL, at location preprocessor. The diagnostic is of type LEVEL, with REASON set
to the reason code if LEVEL is represents a warning, at location
LOCATION, with column number possibly overridden by COLUMN_OVERRIDE LOCATION, with column number possibly overridden by COLUMN_OVERRIDE
if not zero; MSG is the translated message and AP the arguments. if not zero; MSG is the translated message and AP the arguments.
Returns true if a diagnostic was emitted, false otherwise. */ Returns true if a diagnostic was emitted, false otherwise. */
static bool static bool
cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason,
location_t location, unsigned int column_override, location_t location, unsigned int column_override,
const char *msg, va_list *ap) const char *msg, va_list *ap)
{ {
...@@ -1007,6 +1008,8 @@ cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, ...@@ -1007,6 +1008,8 @@ cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level,
location, dlevel); location, dlevel);
if (column_override) if (column_override)
diagnostic_override_column (&diagnostic, column_override); diagnostic_override_column (&diagnostic, column_override);
if (reason == CPP_W_WARNING_DIRECTIVE)
diagnostic_override_option_index (&diagnostic, OPT_Wcpp);
ret = report_diagnostic (&diagnostic); ret = report_diagnostic (&diagnostic);
if (level == CPP_DL_WARNING_SYSHDR) if (level == CPP_DL_WARNING_SYSHDR)
warn_system_headers = save_warn_system_headers; warn_system_headers = save_warn_system_headers;
...@@ -1090,5 +1093,3 @@ dump_queued_macros (cpp_reader *pfile ATTRIBUTE_UNUSED) ...@@ -1090,5 +1093,3 @@ dump_queued_macros (cpp_reader *pfile ATTRIBUTE_UNUSED)
} }
cpp_undefine_queue = NULL; cpp_undefine_queue = NULL;
} }
...@@ -2396,6 +2396,20 @@ set_option (const struct cl_option *option, int value, const char *arg) ...@@ -2396,6 +2396,20 @@ set_option (const struct cl_option *option, int value, const char *arg)
} }
} }
/* Callback function, called when -Werror= enables a warning. */
static void (*warning_as_error_callback) (int) = NULL;
/* Register a callback for enable_warning_as_error calls. */
void
register_warning_as_error_callback (void (*callback) (int))
{
gcc_assert (warning_as_error_callback == NULL || callback == NULL);
warning_as_error_callback = callback;
}
/* Enable a warning option as an error. This is used by -Werror= and /* Enable a warning option as an error. This is used by -Werror= and
also by legacy Werror-implicit-function-declaration. */ also by legacy Werror-implicit-function-declaration. */
...@@ -2415,14 +2429,20 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask) ...@@ -2415,14 +2429,20 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask)
} }
else else
{ {
diagnostic_t kind = value ? DK_ERROR : DK_WARNING; const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
diagnostic_classify_diagnostic (global_dc, option_index, kind); diagnostic_classify_diagnostic (global_dc, option_index, kind);
if (kind == DK_ERROR)
{
const struct cl_option * const option = cl_options + option_index;
/* -Werror=foo implies -Wfoo. */
if (option->var_type == CLVC_BOOLEAN && option->flag_var)
*(int *) option->flag_var = 1;
/* -Werror=foo implies -Wfoo. */ if (warning_as_error_callback)
if (cl_options[option_index].var_type == CLVC_BOOLEAN warning_as_error_callback (option_index);
&& cl_options[option_index].flag_var }
&& kind == DK_ERROR)
*(int *) cl_options[option_index].flag_var = 1;
} }
free (new_option); free (new_option);
} }
...@@ -105,6 +105,7 @@ extern int option_enabled (int opt_idx); ...@@ -105,6 +105,7 @@ extern int option_enabled (int opt_idx);
extern bool get_option_state (int, struct cl_option_state *); extern bool get_option_state (int, struct cl_option_state *);
extern void set_option (const struct cl_option *, int, const char *); extern void set_option (const struct cl_option *, int, const char *);
extern void register_warning_as_error_callback (void (*callback) (int));
extern void enable_warning_as_error (const char *arg, int value, extern void enable_warning_as_error (const char *arg, int value,
unsigned int lang_mask); unsigned int lang_mask);
extern void print_ignored_options (void); extern void print_ignored_options (void);
......
2010-04-07 Iain Sandoe <iains@gcc.gnu.org> 2010-04-07 Simon Baldwin <simonb@google.com>
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
PR objc++/23716 2010-04-07 Iain Sandoe <iains@gcc.gnu.org>
PR objc++/23716
* obj-c++.dg/comp-types-10.mm: Remove XFAIL. * obj-c++.dg/comp-types-10.mm: Remove XFAIL.
2010-04-07 Jason Merrill <jason@redhat.com> 2010-04-07 Jason Merrill <jason@redhat.com>
......
// { dg-do preprocess }
// { dg-options "-fdiagnostics-show-option" }
#warning "Printed" // { dg-warning "\"Printed\" .-Wcpp." }
// { dg-do preprocess }
// { dg-options "-fdiagnostics-show-option -Werror=cpp" }
#warning "Printed" // { dg-error "\"Printed\" .-Wcpp." }
// { dg-do preprocess }
// { dg-options "-fdiagnostics-show-option -Werror -Wno-error=cpp" }
#warning "Printed" // { dg-warning "\"Printed\" .-Wcpp." }
// { dg-do preprocess }
// { dg-options "-fdiagnostics-show-option -Wno-cpp" }
#warning "Not printed" // { dg-bogus "." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=comments" }
/* /* */ // { dg-error "\"\.\*\" within comment .-Wcomments." }
// \
// { dg-error "multi-line comment .-Wcomments." "multi-line" { target *-*-* } 6 }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wcomments" }
/* /* */ // { dg-warning "\"\.\*\" within comment .-Wcomments." }
// \
// { dg-warning "multi-line comment .-Wcomments." "multi-line" { target *-*-* } 6 }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=c++-compat" }
#define not ! // { dg-error "identifier \"not\" is a special operator name in C\\+\\+ .-Wc\\+\\+-compat." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wc++-compat" }
#define not ! // { dg-warning "identifier \"not\" is a special operator name in C\\+\\+ .-Wc\\+\\+-compat." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=deprecated" }
#assert x(x) // { dg-error "#assert is a deprecated GCC extension .-Wdeprecated." }
#if #x(x) // { dg-error "assertions are a deprecated extension .-Wdeprecated." }
#endif
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wdeprecated" }
#assert x(x) // { dg-warning "#assert is a deprecated GCC extension .-Wdeprecated." }
#if #x(x) // { dg-warning "assertions are a deprecated extension .-Wdeprecated." }
#endif
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wtraditional -Werror=long-long" }
#if 0LL // { dg-error "traditional C rejects the \"LL\" suffix .-Wlong-long." }
// { dg-error "use of C99 long long integer constant .-Wlong-long." "use long long" { target *-*-* } 4 }
#endif
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wtraditional -Wlong-long" }
#if 0LL // { dg-warning "traditional C rejects the \"LL\" suffix .-Wlong-long." }
// { dg-warning "use of C99 long long integer constant .-Wlong-long." "use long long" { target *-*-* } 4 }
#endif
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=multichar" }
#if 'abc' // { dg-error "multi-character character constant .-Wmultichar." }
#endif
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wmultichar" }
#if 'abc' // { dg-warning "multi-character character constant .-Wmultichar." }
#endif
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -fextended-identifiers -Wnormalized=nfc" }
\u0F43 // { dg-warning "`.U00000f43' is not in NFC .-Wnormalized=." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -fextended-identifiers -Wnormalized=nfkc" }
\u00AA // { dg-warning "`.U000000aa' is not in NFKC .-Wnormalized=." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -fextended-identifiers -Werror=normalized=" }
// { dg-prune-output ".*-Werror=normalized=: Set -Wnormalized=nfc.*" }
\u0F43 // { dg-error "`.U00000f43' is not in NFC .-Wnormalized=." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=builtin-macro-redefined" }
#ifndef __TIME__
#error "__TIME__ builtin is not defined"
// { dg-bogus "__TIME__ builtin is not defined" "no-time" { target *-*-* } 5 }
#endif
#define __TIME__ "X" // { dg-error "\"__TIME__\" redefined .-Wbuiltin-macro-redefined." }
#define __TIME__ "Y" // { dg-bogus "-Wbuiltin-macro-redefined" }
// { dg-warning "\"__TIME__\" redefined" "not-builtin-1" { target *-*-* } 11 }
// { dg-message "previous definition" "previous-1" { target *-*-* } 9 }
#define X "X"
#define X "Y" // { dg-bogus "-Wbuiltin-macro-redefined" }
// { dg-warning "\"X\" redefined" "not-builtin-2" { target *-*-* } 16 }
// { dg-message "previous definition" "previous-2" { target *-*-* } 15 }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wbuiltin-macro-redefined" }
#ifndef __TIME__
#error "__TIME__ builtin is not defined"
// { dg-bogus "__TIME__ builtin is not defined" "no-time" { target *-*-* } 5 }
#endif
#define __TIME__ "X" // { dg-warning "\"__TIME__\" redefined .-Wbuiltin-macro-redefined." }
#define __TIME__ "Y" // { dg-bogus "-Wbuiltin-macro-redefined" }
// { dg-warning "\"__TIME__\" redefined" "not-builtin-1" { target *-*-* } 11 }
// { dg-message "previous definition" "previous-1" { target *-*-* } 9 }
#define X "X"
#define X "Y" // { dg-bogus "-Wbuiltin-macro-redefined" }
// { dg-warning "\"X\" redefined" "not-builtin-2" { target *-*-* } 16 }
// { dg-message "previous definition" "previous-2" { target *-*-* } 15 }
// { dg-do compile }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=traditional -Wno-deprecated -Wno-long-long" }
#assert x(x) // { dg-error "suggest hiding #assert from traditional C with an indented # .-Wtraditional." }
#define X X // { dg-error "traditional C ignores #define with the # indented .-Wtraditional." }
#if 0
#elif 1 // { dg-error "suggest not using #elif in traditional C .-Wtraditional." }
#endif
#define f(X) X
int f; // { dg-error "function-like macro \"f\" must be used with arguments in traditional C .-Wtraditional." }
#if 0U // { dg-error "traditional C rejects the \"U\" suffix .-Wtraditional." }
#endif
#if +1 // { dg-error " traditional C rejects the unary plus operator .-Wtraditional." }
#endif
char *x = "\x0"; // { dg-error "the meaning of '.x' is different in traditional C .-Wtraditional." }
char *y = "\a"; // { dg-error "the meaning of '.a' is different in traditional C .-Wtraditional." }
char *z = "\u0F43"; // { dg-error "the meaning of '.u' is different in traditional C .-Wtraditional." }
// { dg-do compile }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wtraditional -Wno-deprecated -Wno-long-long" }
#assert x(x) // { dg-warning "suggest hiding #assert from traditional C with an indented # .-Wtraditional." }
#define X X // { dg-warning "traditional C ignores #define with the # indented .-Wtraditional." }
#if 0
#elif 1 // { dg-warning "suggest not using #elif in traditional C .-Wtraditional." }
#endif
#define f(X) X
int f; // { dg-warning "function-like macro \"f\" must be used with arguments in traditional C .-Wtraditional." }
#if 0U // { dg-warning "traditional C rejects the \"U\" suffix .-Wtraditional." }
#endif
#if +1 // { dg-warning " traditional C rejects the unary plus operator .-Wtraditional." }
#endif
char *x = "\x0"; // { dg-warning "the meaning of '.x' is different in traditional C .-Wtraditional." }
char *y = "\a"; // { dg-warning "the meaning of '.a' is different in traditional C .-Wtraditional." }
char *z = "\u0F43"; // { dg-warning "the meaning of '.u' is different in traditional C .-Wtraditional." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -trigraphs -Wtrigraphs" }
??= // { dg-warning "trigraph \\?\\?= converted to # .-Wtrigraphs." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wtrigraphs" }
??= // { dg-warning "trigraph \\?\\?= ignored, use -trigraphs to enable .-Wtrigraphs." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -trigraphs -Werror=trigraphs" }
??= // { dg-error "trigraph \\?\\?= converted to # .-Wtrigraphs." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=trigraphs" }
??= // { dg-error "trigraph \\?\\?= ignored, use -trigraphs to enable .-Wtrigraphs." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=undef" }
#if x // { dg-error "\"x\" is not defined .-Wundef." }
#endif
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wundef" }
#if x // { dg-warning "\"x\" is not defined .-Wundef." }
#endif
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=unused-macros" }
#define X X // { dg-error "macro \"X\" is not used .-Wunused-macros." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wunused-macros" }
#define X X // { dg-warning "macro \"X\" is not used .-Wunused-macros." }
/* { dg-do preprocess } */
/* { dg-options "-ansi -fdiagnostics-show-option -pedantic -Werror=variadic-macros" } */
#define F(...) X /* { dg-error "anonymous variadic macros were introduced in C99 .-Wvariadic-macros." } */
#define G(X...) X /* { dg-error "ISO C does not permit named variadic macros .-Wvariadic-macros." } */
/* { dg-do preprocess } */
/* { dg-options "-ansi -fdiagnostics-show-option -pedantic -Wvariadic-macros" } */
#define F(...) X /* { dg-warning "anonymous variadic macros were introduced in C99 .-Wvariadic-macros." } */
#define G(X...) X /* { dg-warning "ISO C does not permit named variadic macros .-Wvariadic-macros." } */
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option" }
#warning "Printed" // { dg-warning "\"Printed\" .-Wcpp." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=cpp" }
#warning "Printed" // { dg-error "\"Printed\" .-Wcpp." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror -Wno-error=cpp" }
#warning "Printed" // { dg-warning "\"Printed\" .-Wcpp." }
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wno-cpp" }
#warning "Not printed" // { dg-bogus "." }
! { dg-do preprocess }
! { dg-options "-std=f95 -fdiagnostics-show-option" }
#warning "Printed"
! { dg-warning "\"Printed\" .-Wcpp." "" { target *-*-* } 4 }
! { dg-do preprocess }
! { dg-options "-std=f95 -fdiagnostics-show-option -Werror=cpp" }
#warning "Printed"
! { dg-error "\"Printed\" .-Wcpp." "" { target *-*-* } 4 }
! { dg-do preprocess }
! { dg-options "-std=f95 -fdiagnostics-show-option -Werror -Wno-error=cpp" }
#warning "Printed"
! { dg-warning "\"Printed\" .-Wcpp." "" { target *-*-* } 4 }
! { dg-do preprocess }
! { dg-options "-std=f95 -fdiagnostics-show-option -Wno-cpp" }
#warning "Not printed"
! { dg-bogus "." "" { target *-*-* } 4 }
2010-04-07 Simon Baldwin <simonb@google.com>
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
2010-04-06 Jakub Jelinek <jakub@redhat.com> 2010-04-06 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/43642 PR preprocessor/43642
......
...@@ -249,8 +249,15 @@ po/$(PACKAGE).pot: $(libcpp_a_SOURCES) ...@@ -249,8 +249,15 @@ po/$(PACKAGE).pot: $(libcpp_a_SOURCES)
$(mkinstalldirs) $(srcdir)/po $(mkinstalldirs) $(srcdir)/po
$(XGETTEXT) --default-domain=$(PACKAGE) \ $(XGETTEXT) --default-domain=$(PACKAGE) \
--keyword=_ --keyword=N_ \ --keyword=_ --keyword=N_ \
--keyword=cpp_error:3 --keyword=cpp_errno:3 \ --keyword=cpp_error:3 \
--keyword=cpp_warning:3 \
--keyword=cpp_pedwarning:3 \
--keyword=cpp_warning_syshdr:3 \
--keyword=cpp_error_with_line:5 \ --keyword=cpp_error_with_line:5 \
--keyword=cpp_warning_with_line:5 \
--keyword=cpp_pedwarning_with_line:5 \
--keyword=cpp_warning_with_line_syshdr:5 \
--keyword=cpp_errno:3 \
--keyword=SYNTAX_ERROR --keyword=SYNTAX_ERROR2 \ --keyword=SYNTAX_ERROR --keyword=SYNTAX_ERROR2 \
--copyright-holder="Free Software Foundation, Inc." \ --copyright-holder="Free Software Foundation, Inc." \
--msgid-bugs-address="http://gcc.gnu.org/bugs.html" \ --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
......
...@@ -993,9 +993,9 @@ _cpp_valid_ucn (cpp_reader *pfile, const uchar **pstr, ...@@ -993,9 +993,9 @@ _cpp_valid_ucn (cpp_reader *pfile, const uchar **pstr,
cpp_error (pfile, CPP_DL_WARNING, cpp_error (pfile, CPP_DL_WARNING,
"universal character names are only valid in C++ and C99"); "universal character names are only valid in C++ and C99");
else if (CPP_WTRADITIONAL (pfile) && identifier_pos == 0) else if (CPP_WTRADITIONAL (pfile) && identifier_pos == 0)
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_TRADITIONAL,
"the meaning of '\\%c' is different in traditional C", "the meaning of '\\%c' is different in traditional C",
(int) str[-1]); (int) str[-1]);
if (str[-1] == 'u') if (str[-1] == 'u')
length = 4; length = 4;
...@@ -1174,8 +1174,8 @@ convert_hex (cpp_reader *pfile, const uchar *from, const uchar *limit, ...@@ -1174,8 +1174,8 @@ convert_hex (cpp_reader *pfile, const uchar *from, const uchar *limit,
size_t mask = width_to_mask (width); size_t mask = width_to_mask (width);
if (CPP_WTRADITIONAL (pfile)) if (CPP_WTRADITIONAL (pfile))
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_TRADITIONAL,
"the meaning of '\\x' is different in traditional C"); "the meaning of '\\x' is different in traditional C");
from++; /* Skip 'x'. */ from++; /* Skip 'x'. */
while (from < limit) while (from < limit)
...@@ -1302,8 +1302,8 @@ convert_escape (cpp_reader *pfile, const uchar *from, const uchar *limit, ...@@ -1302,8 +1302,8 @@ convert_escape (cpp_reader *pfile, const uchar *from, const uchar *limit,
case 'a': case 'a':
if (CPP_WTRADITIONAL (pfile)) if (CPP_WTRADITIONAL (pfile))
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_TRADITIONAL,
"the meaning of '\\a' is different in traditional C"); "the meaning of '\\a' is different in traditional C");
c = charconsts[0]; c = charconsts[0];
break; break;
...@@ -1509,7 +1509,7 @@ narrow_str_to_charconst (cpp_reader *pfile, cpp_string str, ...@@ -1509,7 +1509,7 @@ narrow_str_to_charconst (cpp_reader *pfile, cpp_string str,
"character constant too long for its type"); "character constant too long for its type");
} }
else if (i > 1 && CPP_OPTION (pfile, warn_multichar)) else if (i > 1 && CPP_OPTION (pfile, warn_multichar))
cpp_error (pfile, CPP_DL_WARNING, "multi-character character constant"); cpp_warning (pfile, CPP_W_MULTICHAR, "multi-character character constant");
/* Multichar constants are of type int and therefore signed. */ /* Multichar constants are of type int and therefore signed. */
if (i > 1) if (i > 1)
......
...@@ -104,7 +104,7 @@ static const char *parse_include (cpp_reader *, int *, const cpp_token ***, ...@@ -104,7 +104,7 @@ static const char *parse_include (cpp_reader *, int *, const cpp_token ***,
static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *); static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *);
static unsigned int read_flag (cpp_reader *, unsigned int); static unsigned int read_flag (cpp_reader *, unsigned int);
static bool strtolinenum (const uchar *, size_t, linenum_type *, bool *); static bool strtolinenum (const uchar *, size_t, linenum_type *, bool *);
static void do_diagnostic (cpp_reader *, int, int); static void do_diagnostic (cpp_reader *, int, int, int);
static cpp_hashnode *lex_macro_node (cpp_reader *, bool); static cpp_hashnode *lex_macro_node (cpp_reader *, bool);
static int undefine_macros (cpp_reader *, cpp_hashnode *, void *); static int undefine_macros (cpp_reader *, cpp_hashnode *, void *);
static void do_include_common (cpp_reader *, enum include_type); static void do_include_common (cpp_reader *, enum include_type);
...@@ -355,8 +355,8 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) ...@@ -355,8 +355,8 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented)
else if (((dir->flags & DEPRECATED) != 0 else if (((dir->flags & DEPRECATED) != 0
|| (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc))) || (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc)))
&& CPP_OPTION (pfile, warn_deprecated)) && CPP_OPTION (pfile, warn_deprecated))
cpp_error (pfile, CPP_DL_WARNING, "#%s is a deprecated GCC extension", cpp_warning (pfile, CPP_W_DEPRECATED,
dir->name); "#%s is a deprecated GCC extension", dir->name);
} }
/* Traditionally, a directive is ignored unless its # is in /* Traditionally, a directive is ignored unless its # is in
...@@ -368,16 +368,16 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) ...@@ -368,16 +368,16 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented)
if (CPP_WTRADITIONAL (pfile)) if (CPP_WTRADITIONAL (pfile))
{ {
if (dir == &dtable[T_ELIF]) if (dir == &dtable[T_ELIF])
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_TRADITIONAL,
"suggest not using #elif in traditional C"); "suggest not using #elif in traditional C");
else if (indented && dir->origin == KANDR) else if (indented && dir->origin == KANDR)
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_TRADITIONAL,
"traditional C ignores #%s with the # indented", "traditional C ignores #%s with the # indented",
dir->name); dir->name);
else if (!indented && dir->origin != KANDR) else if (!indented && dir->origin != KANDR)
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_TRADITIONAL,
"suggest hiding #%s from traditional C with an indented #", "suggest hiding #%s from traditional C with an indented #",
dir->name); dir->name);
} }
} }
...@@ -1045,7 +1045,7 @@ _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, ...@@ -1045,7 +1045,7 @@ _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason,
/* Report a warning or error detected by the program we are /* Report a warning or error detected by the program we are
processing. Use the directive's tokens in the error message. */ processing. Use the directive's tokens in the error message. */
static void static void
do_diagnostic (cpp_reader *pfile, int code, int print_dir) do_diagnostic (cpp_reader *pfile, int code, int reason, int print_dir)
{ {
const unsigned char *dir_name; const unsigned char *dir_name;
unsigned char *line; unsigned char *line;
...@@ -1059,21 +1059,26 @@ do_diagnostic (cpp_reader *pfile, int code, int print_dir) ...@@ -1059,21 +1059,26 @@ do_diagnostic (cpp_reader *pfile, int code, int print_dir)
line = cpp_output_line_to_string (pfile, dir_name); line = cpp_output_line_to_string (pfile, dir_name);
pfile->state.prevent_expansion--; pfile->state.prevent_expansion--;
cpp_error_with_line (pfile, code, src_loc, 0, "%s", line); if (code == CPP_DL_WARNING_SYSHDR && reason)
cpp_warning_with_line_syshdr (pfile, reason, src_loc, 0, "%s", line);
else if (code == CPP_DL_WARNING && reason)
cpp_warning_with_line (pfile, reason, src_loc, 0, "%s", line);
else
cpp_error_with_line (pfile, code, src_loc, 0, "%s", line);
free (line); free (line);
} }
static void static void
do_error (cpp_reader *pfile) do_error (cpp_reader *pfile)
{ {
do_diagnostic (pfile, CPP_DL_ERROR, 1); do_diagnostic (pfile, CPP_DL_ERROR, 0, 1);
} }
static void static void
do_warning (cpp_reader *pfile) do_warning (cpp_reader *pfile)
{ {
/* We want #warning diagnostics to be emitted in system headers too. */ /* We want #warning diagnostics to be emitted in system headers too. */
do_diagnostic (pfile, CPP_DL_WARNING_SYSHDR, 1); do_diagnostic (pfile, CPP_DL_WARNING_SYSHDR, CPP_W_WARNING_DIRECTIVE, 1);
} }
/* Report program identification. */ /* Report program identification. */
...@@ -1595,7 +1600,7 @@ do_pragma_dependency (cpp_reader *pfile) ...@@ -1595,7 +1600,7 @@ do_pragma_dependency (cpp_reader *pfile)
if (cpp_get_token (pfile)->type != CPP_EOF) if (cpp_get_token (pfile)->type != CPP_EOF)
{ {
_cpp_backup_tokens (pfile, 1); _cpp_backup_tokens (pfile, 1);
do_diagnostic (pfile, CPP_DL_WARNING, 0); do_diagnostic (pfile, CPP_DL_WARNING, 0, 0);
} }
} }
......
...@@ -28,16 +28,16 @@ along with this program; see the file COPYING3. If not see ...@@ -28,16 +28,16 @@ along with this program; see the file COPYING3. If not see
#include "cpplib.h" #include "cpplib.h"
#include "internal.h" #include "internal.h"
/* Print an error at the location of the previously lexed token. */ /* Print a diagnostic at the location of the previously lexed token. */
bool
cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) ATTRIBUTE_FPTR_PRINTF(4,0)
static bool
cpp_diagnostic (cpp_reader * pfile, int level, int reason,
const char *msgid, va_list *ap)
{ {
source_location src_loc; source_location src_loc;
va_list ap;
bool ret; bool ret;
va_start (ap, msgid);
if (CPP_OPTION (pfile, traditional)) if (CPP_OPTION (pfile, traditional))
{ {
if (pfile->state.in_directive) if (pfile->state.in_directive)
...@@ -61,13 +61,95 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) ...@@ -61,13 +61,95 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
if (!pfile->cb.error) if (!pfile->cb.error)
abort (); abort ();
ret = pfile->cb.error (pfile, level, src_loc, 0, _(msgid), &ap); ret = pfile->cb.error (pfile, level, reason, src_loc, 0, _(msgid), ap);
return ret;
}
/* Print a warning or error, depending on the value of LEVEL. */
bool
cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
{
va_list ap;
bool ret;
va_start (ap, msgid);
ret = cpp_diagnostic (pfile, level, CPP_W_NONE, msgid, &ap);
va_end (ap); va_end (ap);
return ret; return ret;
} }
/* Print an error at a specific location. */ /* Print a warning. The warning reason may be given in REASON. */
bool
cpp_warning (cpp_reader * pfile, int reason, const char *msgid, ...)
{
va_list ap;
bool ret;
va_start (ap, msgid);
ret = cpp_diagnostic (pfile, CPP_DL_WARNING, reason, msgid, &ap);
va_end (ap);
return ret;
}
/* Print a pedantic warning. The warning reason may be given in REASON. */
bool
cpp_pedwarning (cpp_reader * pfile, int reason, const char *msgid, ...)
{
va_list ap;
bool ret;
va_start (ap, msgid);
ret = cpp_diagnostic (pfile, CPP_DL_PEDWARN, reason, msgid, &ap);
va_end (ap);
return ret;
}
/* Print a warning, including system headers. The warning reason may be
given in REASON. */
bool
cpp_warning_syshdr (cpp_reader * pfile, int reason, const char *msgid, ...)
{
va_list ap;
bool ret;
va_start (ap, msgid);
ret = cpp_diagnostic (pfile, CPP_DL_WARNING_SYSHDR, reason, msgid, &ap);
va_end (ap);
return ret;
}
/* Print a diagnostic at a specific location. */
ATTRIBUTE_FPTR_PRINTF(6,0)
static bool
cpp_diagnostic_with_line (cpp_reader * pfile, int level, int reason,
source_location src_loc, unsigned int column,
const char *msgid, va_list *ap)
{
bool ret;
if (!pfile->cb.error)
abort ();
ret = pfile->cb.error (pfile, level, reason, src_loc, column, _(msgid), ap);
return ret;
}
/* Print a warning or error, depending on the value of LEVEL. */
bool bool
cpp_error_with_line (cpp_reader *pfile, int level, cpp_error_with_line (cpp_reader *pfile, int level,
source_location src_loc, unsigned int column, source_location src_loc, unsigned int column,
...@@ -75,17 +157,77 @@ cpp_error_with_line (cpp_reader *pfile, int level, ...@@ -75,17 +157,77 @@ cpp_error_with_line (cpp_reader *pfile, int level,
{ {
va_list ap; va_list ap;
bool ret; bool ret;
va_start (ap, msgid); va_start (ap, msgid);
if (!pfile->cb.error) ret = cpp_diagnostic_with_line (pfile, level, CPP_W_NONE, src_loc,
abort (); column, msgid, &ap);
ret = pfile->cb.error (pfile, level, src_loc, column, _(msgid), &ap);
va_end (ap);
return ret;
}
/* Print a warning. The warning reason may be given in REASON. */
bool
cpp_warning_with_line (cpp_reader *pfile, int reason,
source_location src_loc, unsigned int column,
const char *msgid, ...)
{
va_list ap;
bool ret;
va_start (ap, msgid);
ret = cpp_diagnostic_with_line (pfile, CPP_DL_WARNING, reason, src_loc,
column, msgid, &ap);
va_end (ap);
return ret;
}
/* Print a pedantic warning. The warning reason may be given in REASON. */
bool
cpp_pedwarning_with_line (cpp_reader *pfile, int reason,
source_location src_loc, unsigned int column,
const char *msgid, ...)
{
va_list ap;
bool ret;
va_start (ap, msgid);
ret = cpp_diagnostic_with_line (pfile, CPP_DL_PEDWARN, reason, src_loc,
column, msgid, &ap);
va_end (ap); va_end (ap);
return ret; return ret;
} }
/* Print a warning, including system headers. The warning reason may be
given in REASON. */
bool
cpp_warning_with_line_syshdr (cpp_reader *pfile, int reason,
source_location src_loc, unsigned int column,
const char *msgid, ...)
{
va_list ap;
bool ret;
va_start (ap, msgid);
ret = cpp_diagnostic_with_line (pfile, CPP_DL_WARNING_SYSHDR, reason, src_loc,
column, msgid, &ap);
va_end (ap);
return ret;
}
/* Print a warning or error, depending on the value of LEVEL. Include
information from errno. */
bool bool
cpp_errno (cpp_reader *pfile, int level, const char *msgid) cpp_errno (cpp_reader *pfile, int level, const char *msgid)
{ {
......
...@@ -371,9 +371,9 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token) ...@@ -371,9 +371,9 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
if (limit != str if (limit != str
&& CPP_WTRADITIONAL (pfile) && CPP_WTRADITIONAL (pfile)
&& ! cpp_sys_macro_p (pfile)) && ! cpp_sys_macro_p (pfile))
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_TRADITIONAL,
"traditional C rejects the \"%.*s\" suffix", "traditional C rejects the \"%.*s\" suffix",
(int) (limit - str), str); (int) (limit - str), str);
/* A suffix for double is a GCC extension via decimal float support. /* A suffix for double is a GCC extension via decimal float support.
If the suffix also specifies an imaginary value we'll catch that If the suffix also specifies an imaginary value we'll catch that
...@@ -417,21 +417,27 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token) ...@@ -417,21 +417,27 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
if (CPP_WTRADITIONAL (pfile) && ! cpp_sys_macro_p (pfile)) if (CPP_WTRADITIONAL (pfile) && ! cpp_sys_macro_p (pfile))
{ {
int u_or_i = (result & (CPP_N_UNSIGNED|CPP_N_IMAGINARY)); int u_or_i = (result & (CPP_N_UNSIGNED|CPP_N_IMAGINARY));
int large = (result & CPP_N_WIDTH) == CPP_N_LARGE; int large = (result & CPP_N_WIDTH) == CPP_N_LARGE
&& CPP_OPTION (pfile, warn_long_long);
if (u_or_i || (large && CPP_OPTION (pfile, warn_long_long))) if (u_or_i || large)
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, large ? CPP_W_LONG_LONG : CPP_W_TRADITIONAL,
"traditional C rejects the \"%.*s\" suffix", "traditional C rejects the \"%.*s\" suffix",
(int) (limit - str), str); (int) (limit - str), str);
} }
if ((result & CPP_N_WIDTH) == CPP_N_LARGE if ((result & CPP_N_WIDTH) == CPP_N_LARGE
&& CPP_OPTION (pfile, warn_long_long)) && CPP_OPTION (pfile, warn_long_long))
cpp_error (pfile, {
CPP_OPTION (pfile, c99) ? CPP_DL_WARNING : CPP_DL_PEDWARN, const char *message = CPP_OPTION (pfile, cplusplus)
CPP_OPTION (pfile, cplusplus) ? N_("use of C++0x long long integer constant")
? "use of C++0x long long integer constant" : N_("use of C99 long long integer constant");
: "use of C99 long long integer constant");
if (CPP_OPTION (pfile, c99))
cpp_warning (pfile, CPP_W_LONG_LONG, message);
else
cpp_pedwarning (pfile, CPP_W_LONG_LONG, message);
}
result |= CPP_N_INTEGER; result |= CPP_N_INTEGER;
} }
...@@ -792,8 +798,8 @@ eval_token (cpp_reader *pfile, const cpp_token *token) ...@@ -792,8 +798,8 @@ eval_token (cpp_reader *pfile, const cpp_token *token)
result.high = 0; result.high = 0;
result.low = 0; result.low = 0;
if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval) if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval)
cpp_error (pfile, CPP_DL_WARNING, "\"%s\" is not defined", cpp_warning (pfile, CPP_W_UNDEF, "\"%s\" is not defined",
NODE_NAME (token->val.node.node)); NODE_NAME (token->val.node.node));
} }
break; break;
...@@ -806,8 +812,8 @@ eval_token (cpp_reader *pfile, const cpp_token *token) ...@@ -806,8 +812,8 @@ eval_token (cpp_reader *pfile, const cpp_token *token)
cpp_error (pfile, CPP_DL_PEDWARN, cpp_error (pfile, CPP_DL_PEDWARN,
"assertions are a GCC extension"); "assertions are a GCC extension");
else if (CPP_OPTION (pfile, warn_deprecated)) else if (CPP_OPTION (pfile, warn_deprecated))
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_DEPRECATED,
"assertions are a deprecated extension"); "assertions are a deprecated extension");
} }
_cpp_test_assertion (pfile, &temp); _cpp_test_assertion (pfile, &temp);
result.high = 0; result.high = 0;
...@@ -1502,8 +1508,8 @@ num_unary_op (cpp_reader *pfile, cpp_num num, enum cpp_ttype op) ...@@ -1502,8 +1508,8 @@ num_unary_op (cpp_reader *pfile, cpp_num num, enum cpp_ttype op)
{ {
case CPP_UPLUS: case CPP_UPLUS:
if (CPP_WTRADITIONAL (pfile) && !pfile->state.skip_eval) if (CPP_WTRADITIONAL (pfile) && !pfile->state.skip_eval)
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_TRADITIONAL,
"traditional C rejects the unary plus operator"); "traditional C rejects the unary plus operator");
num.overflow = false; num.overflow = false;
break; break;
......
...@@ -497,9 +497,9 @@ struct cpp_callbacks ...@@ -497,9 +497,9 @@ struct cpp_callbacks
/* Called to emit a diagnostic. This callback receives the /* Called to emit a diagnostic. This callback receives the
translated message. */ translated message. */
bool (*error) (cpp_reader *, int, source_location, unsigned int, bool (*error) (cpp_reader *, int, int, source_location, unsigned int,
const char *, va_list *) const char *, va_list *)
ATTRIBUTE_FPTR_PRINTF(5,0); ATTRIBUTE_FPTR_PRINTF(6,0);
/* Callbacks for when a macro is expanded, or tested (whether /* Callbacks for when a macro is expanded, or tested (whether
defined or not at the time) in #ifdef, #ifndef or "defined". */ defined or not at the time) in #ifdef, #ifndef or "defined". */
...@@ -829,25 +829,57 @@ cpp_num cpp_num_sign_extend (cpp_num, size_t); ...@@ -829,25 +829,57 @@ cpp_num cpp_num_sign_extend (cpp_num, size_t);
position in the translation unit with it, use cpp_error_with_line position in the translation unit with it, use cpp_error_with_line
with a line number of zero. */ with a line number of zero. */
/* Warning, an error with -Werror. */ enum {
#define CPP_DL_WARNING 0x00 /* Warning, an error with -Werror. */
/* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */ CPP_DL_WARNING = 0,
#define CPP_DL_WARNING_SYSHDR 0x01 /* Same as CPP_DL_WARNING, except it is not suppressed in system headers. */
/* Warning, an error with -pedantic-errors or -Werror. */ CPP_DL_WARNING_SYSHDR,
#define CPP_DL_PEDWARN 0x02 /* Warning, an error with -pedantic-errors or -Werror. */
/* An error. */ CPP_DL_PEDWARN,
#define CPP_DL_ERROR 0x03 /* An error. */
/* An internal consistency check failed. Prints "internal error: ", CPP_DL_ERROR,
otherwise the same as CPP_DL_ERROR. */ /* An internal consistency check failed. Prints "internal error: ",
#define CPP_DL_ICE 0x04 otherwise the same as CPP_DL_ERROR. */
/* An informative note following a warning. */ CPP_DL_ICE,
#define CPP_DL_NOTE 0x05 /* An informative note following a warning. */
/* A fatal error. */ CPP_DL_NOTE,
#define CPP_DL_FATAL 0x06 /* A fatal error. */
CPP_DL_FATAL
};
/* Warning reason codes. Use a reason code of zero for unclassified warnings
and errors that are not warnings. */
enum {
CPP_W_NONE = 0,
CPP_W_DEPRECATED,
CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS,
CPP_W_TRIGRAPHS,
CPP_W_MULTICHAR,
CPP_W_TRADITIONAL,
CPP_W_LONG_LONG,
CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE,
CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED,
CPP_W_DOLLARS,
CPP_W_UNDEF,
CPP_W_UNUSED_MACROS,
CPP_W_CXX_OPERATOR_NAMES,
CPP_W_NORMALIZE,
CPP_W_INVALID_PCH,
CPP_W_WARNING_DIRECTIVE
};
/* Output a diagnostic of some kind. */ /* Output a diagnostic of some kind. */
extern bool cpp_error (cpp_reader *, int, const char *msgid, ...) extern bool cpp_error (cpp_reader *, int, const char *msgid, ...)
ATTRIBUTE_PRINTF_3; ATTRIBUTE_PRINTF_3;
extern bool cpp_warning (cpp_reader *, int, const char *msgid, ...)
ATTRIBUTE_PRINTF_3;
extern bool cpp_pedwarning (cpp_reader *, int, const char *msgid, ...)
ATTRIBUTE_PRINTF_3;
extern bool cpp_warning_syshdr (cpp_reader *, int, const char *msgid, ...)
ATTRIBUTE_PRINTF_3;
/* Output a diagnostic with "MSGID: " preceding the /* Output a diagnostic with "MSGID: " preceding the
error string of errno. No location is printed. */ error string of errno. No location is printed. */
...@@ -856,8 +888,18 @@ extern bool cpp_errno (cpp_reader *, int, const char *msgid); ...@@ -856,8 +888,18 @@ extern bool cpp_errno (cpp_reader *, int, const char *msgid);
/* Same as cpp_error, except additionally specifies a position as a /* Same as cpp_error, except additionally specifies a position as a
(translation unit) physical line and physical column. If the line is (translation unit) physical line and physical column. If the line is
zero, then no location is printed. */ zero, then no location is printed. */
extern bool cpp_error_with_line (cpp_reader *, int, source_location, unsigned, extern bool cpp_error_with_line (cpp_reader *, int, source_location,
const char *msgid, ...) ATTRIBUTE_PRINTF_5; unsigned, const char *msgid, ...)
ATTRIBUTE_PRINTF_5;
extern bool cpp_warning_with_line (cpp_reader *, int, source_location,
unsigned, const char *msgid, ...)
ATTRIBUTE_PRINTF_5;
extern bool cpp_pedwarning_with_line (cpp_reader *, int, source_location,
unsigned, const char *msgid, ...)
ATTRIBUTE_PRINTF_5;
extern bool cpp_warning_with_line_syshdr (cpp_reader *, int, source_location,
unsigned, const char *msgid, ...)
ATTRIBUTE_PRINTF_5;
/* In lex.c */ /* In lex.c */
extern int cpp_ideq (const cpp_token *, const char *); extern int cpp_ideq (const cpp_token *, const char *);
......
...@@ -301,14 +301,16 @@ _cpp_process_line_notes (cpp_reader *pfile, int in_comment) ...@@ -301,14 +301,16 @@ _cpp_process_line_notes (cpp_reader *pfile, int in_comment)
&& (!in_comment || warn_in_comment (pfile, note))) && (!in_comment || warn_in_comment (pfile, note)))
{ {
if (CPP_OPTION (pfile, trigraphs)) if (CPP_OPTION (pfile, trigraphs))
cpp_error_with_line (pfile, CPP_DL_WARNING, pfile->line_table->highest_line, col, cpp_warning_with_line (pfile, CPP_W_TRIGRAPHS,
"trigraph ??%c converted to %c", pfile->line_table->highest_line, col,
note->type, "trigraph ??%c converted to %c",
(int) _cpp_trigraph_map[note->type]); note->type,
(int) _cpp_trigraph_map[note->type]);
else else
{ {
cpp_error_with_line cpp_warning_with_line
(pfile, CPP_DL_WARNING, pfile->line_table->highest_line, col, (pfile, CPP_W_TRIGRAPHS,
pfile->line_table->highest_line, col,
"trigraph ??%c ignored, use -trigraphs to enable", "trigraph ??%c ignored, use -trigraphs to enable",
note->type); note->type);
} }
...@@ -355,9 +357,10 @@ _cpp_skip_block_comment (cpp_reader *pfile) ...@@ -355,9 +357,10 @@ _cpp_skip_block_comment (cpp_reader *pfile)
&& cur[0] == '*' && cur[1] != '/') && cur[0] == '*' && cur[1] != '/')
{ {
buffer->cur = cur; buffer->cur = cur;
cpp_error_with_line (pfile, CPP_DL_WARNING, cpp_warning_with_line (pfile, CPP_W_COMMENTS,
pfile->line_table->highest_line, CPP_BUF_COL (buffer), pfile->line_table->highest_line,
"\"/*\" within comment"); CPP_BUF_COL (buffer),
"\"/*\" within comment");
} }
} }
else if (c == '\n') else if (c == '\n')
...@@ -460,11 +463,11 @@ warn_about_normalization (cpp_reader *pfile, ...@@ -460,11 +463,11 @@ warn_about_normalization (cpp_reader *pfile,
sz = cpp_spell_token (pfile, token, buf, false) - buf; sz = cpp_spell_token (pfile, token, buf, false) - buf;
if (NORMALIZE_STATE_RESULT (s) == normalized_C) if (NORMALIZE_STATE_RESULT (s) == normalized_C)
cpp_error_with_line (pfile, CPP_DL_WARNING, token->src_loc, 0, cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0,
"`%.*s' is not in NFKC", (int) sz, buf); "`%.*s' is not in NFKC", (int) sz, buf);
else else
cpp_error_with_line (pfile, CPP_DL_WARNING, token->src_loc, 0, cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0,
"`%.*s' is not in NFC", (int) sz, buf); "`%.*s' is not in NFC", (int) sz, buf);
} }
} }
...@@ -545,9 +548,9 @@ lex_identifier_intern (cpp_reader *pfile, const uchar *base) ...@@ -545,9 +548,9 @@ lex_identifier_intern (cpp_reader *pfile, const uchar *base)
/* For -Wc++-compat, warn about use of C++ named operators. */ /* For -Wc++-compat, warn about use of C++ named operators. */
if (result->flags & NODE_WARN_OPERATOR) if (result->flags & NODE_WARN_OPERATOR)
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_CXX_OPERATOR_NAMES,
"identifier \"%s\" is a special operator name in C++", "identifier \"%s\" is a special operator name in C++",
NODE_NAME (result)); NODE_NAME (result));
} }
return result; return result;
...@@ -622,9 +625,9 @@ lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn, ...@@ -622,9 +625,9 @@ lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn,
/* For -Wc++-compat, warn about use of C++ named operators. */ /* For -Wc++-compat, warn about use of C++ named operators. */
if (result->flags & NODE_WARN_OPERATOR) if (result->flags & NODE_WARN_OPERATOR)
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_CXX_OPERATOR_NAMES,
"identifier \"%s\" is a special operator name in C++", "identifier \"%s\" is a special operator name in C++",
NODE_NAME (result)); NODE_NAME (result));
} }
return result; return result;
...@@ -1531,7 +1534,7 @@ _cpp_lex_direct (cpp_reader *pfile) ...@@ -1531,7 +1534,7 @@ _cpp_lex_direct (cpp_reader *pfile)
} }
if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments)) if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments))
cpp_error (pfile, CPP_DL_WARNING, "multi-line comment"); cpp_warning (pfile, CPP_W_COMMENTS, "multi-line comment");
} }
else if (c == '=') else if (c == '=')
{ {
......
...@@ -83,8 +83,8 @@ _cpp_warn_if_unused_macro (cpp_reader *pfile, cpp_hashnode *node, ...@@ -83,8 +83,8 @@ _cpp_warn_if_unused_macro (cpp_reader *pfile, cpp_hashnode *node,
if (!macro->used if (!macro->used
&& MAIN_FILE_P (linemap_lookup (pfile->line_table, macro->line))) && MAIN_FILE_P (linemap_lookup (pfile->line_table, macro->line)))
cpp_error_with_line (pfile, CPP_DL_WARNING, macro->line, 0, cpp_warning_with_line (pfile, CPP_W_UNUSED_MACROS, macro->line, 0,
"macro \"%s\" is not used", NODE_NAME (node)); "macro \"%s\" is not used", NODE_NAME (node));
} }
return 1; return 1;
...@@ -860,9 +860,9 @@ enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, ...@@ -860,9 +860,9 @@ enter_macro_context (cpp_reader *pfile, cpp_hashnode *node,
if (buff == NULL) if (buff == NULL)
{ {
if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr) if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr)
cpp_error (pfile, CPP_DL_WARNING, cpp_warning (pfile, CPP_W_TRADITIONAL,
"function-like macro \"%s\" must be used with arguments in traditional C", "function-like macro \"%s\" must be used with arguments in traditional C",
NODE_NAME (node)); NODE_NAME (node));
if (pragma_buff) if (pragma_buff)
_cpp_release_buff (pfile, pragma_buff); _cpp_release_buff (pfile, pragma_buff);
...@@ -1585,13 +1585,14 @@ parse_params (cpp_reader *pfile, cpp_macro *macro) ...@@ -1585,13 +1585,14 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
if (! CPP_OPTION (pfile, c99) if (! CPP_OPTION (pfile, c99)
&& CPP_OPTION (pfile, pedantic) && CPP_OPTION (pfile, pedantic)
&& CPP_OPTION (pfile, warn_variadic_macros)) && CPP_OPTION (pfile, warn_variadic_macros))
cpp_error (pfile, CPP_DL_PEDWARN, cpp_pedwarning
"anonymous variadic macros were introduced in C99"); (pfile, CPP_W_VARIADIC_MACROS,
"anonymous variadic macros were introduced in C99");
} }
else if (CPP_OPTION (pfile, pedantic) else if (CPP_OPTION (pfile, pedantic)
&& CPP_OPTION (pfile, warn_variadic_macros)) && CPP_OPTION (pfile, warn_variadic_macros))
cpp_error (pfile, CPP_DL_PEDWARN, cpp_pedwarning (pfile, CPP_W_VARIADIC_MACROS,
"ISO C does not permit named variadic macros"); "ISO C does not permit named variadic macros");
/* We're at the end, and just expect a closing parenthesis. */ /* We're at the end, and just expect a closing parenthesis. */
token = _cpp_lex_token (pfile); token = _cpp_lex_token (pfile);
...@@ -1894,10 +1895,14 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) ...@@ -1894,10 +1895,14 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
if (warn_of_redefinition (pfile, node, macro)) if (warn_of_redefinition (pfile, node, macro))
{ {
const int reason = (node->flags & NODE_BUILTIN)
? CPP_W_BUILTIN_MACRO_REDEFINED : CPP_W_NONE;
bool warned; bool warned;
warned = cpp_error_with_line (pfile, CPP_DL_PEDWARN,
pfile->directive_line, 0, warned = cpp_pedwarning_with_line (pfile, reason,
"\"%s\" redefined", NODE_NAME (node)); pfile->directive_line, 0,
"\"%s\" redefined",
NODE_NAME (node));
if (warned && node->type == NT_MACRO && !(node->flags & NODE_BUILTIN)) if (warned && node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
cpp_error_with_line (pfile, CPP_DL_NOTE, cpp_error_with_line (pfile, CPP_DL_NOTE,
......
...@@ -613,9 +613,9 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd) ...@@ -613,9 +613,9 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
|| h->flags & NODE_POISONED) || h->flags & NODE_POISONED)
{ {
if (CPP_OPTION (r, warn_invalid_pch)) if (CPP_OPTION (r, warn_invalid_pch))
cpp_error (r, CPP_DL_WARNING_SYSHDR, cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
"%s: not used because `%.*s' is poisoned", "%s: not used because `%.*s' is poisoned",
name, m.name_length, namebuf); name, m.name_length, namebuf);
goto fail; goto fail;
} }
...@@ -635,9 +635,9 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd) ...@@ -635,9 +635,9 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
continue; continue;
if (CPP_OPTION (r, warn_invalid_pch)) if (CPP_OPTION (r, warn_invalid_pch))
cpp_error (r, CPP_DL_WARNING_SYSHDR, cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
"%s: not used because `%.*s' not defined", "%s: not used because `%.*s' not defined",
name, m.name_length, namebuf); name, m.name_length, namebuf);
goto fail; goto fail;
} }
...@@ -647,7 +647,7 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd) ...@@ -647,7 +647,7 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
|| memcmp (namebuf, newdefn, m.definition_length) != 0) || memcmp (namebuf, newdefn, m.definition_length) != 0)
{ {
if (CPP_OPTION (r, warn_invalid_pch)) if (CPP_OPTION (r, warn_invalid_pch))
cpp_error (r, CPP_DL_WARNING_SYSHDR, cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
"%s: not used because `%.*s' defined as `%s' not `%.*s'", "%s: not used because `%.*s' defined as `%s' not `%.*s'",
name, m.name_length, namebuf, newdefn + m.name_length, name, m.name_length, namebuf, newdefn + m.name_length,
m.definition_length - m.name_length, m.definition_length - m.name_length,
...@@ -688,9 +688,9 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd) ...@@ -688,9 +688,9 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
else else
{ {
if (CPP_OPTION (r, warn_invalid_pch)) if (CPP_OPTION (r, warn_invalid_pch))
cpp_error (r, CPP_DL_WARNING_SYSHDR, cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
"%s: not used because `%s' is defined", "%s: not used because `%s' is defined",
name, first); name, first);
goto fail; goto fail;
} }
} }
...@@ -708,9 +708,9 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd) ...@@ -708,9 +708,9 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
if (counter && r->counter) if (counter && r->counter)
{ {
if (CPP_OPTION (r, warn_invalid_pch)) if (CPP_OPTION (r, warn_invalid_pch))
cpp_error (r, CPP_DL_WARNING_SYSHDR, cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
"%s: not used because `__COUNTER__' is invalid", "%s: not used because `__COUNTER__' is invalid",
name); name);
goto fail; goto fail;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment