summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog22
-rw-r--r--gcc/c-common.c50
-rw-r--r--gcc/c-opts.c87
-rw-r--r--gcc/c-tree.h4
-rw-r--r--gcc/common.opt4
-rw-r--r--gcc/diagnostic.h5
-rw-r--r--gcc/doc/invoke.texi7
-rw-r--r--gcc/fortran/ChangeLog5
-rw-r--r--gcc/fortran/cpp.c13
-rw-r--r--gcc/opts.c32
-rw-r--r--gcc/opts.h1
-rw-r--r--gcc/testsuite/ChangeLog45
-rw-r--r--gcc/testsuite/g++.dg/cpp/warning-directive-1.C4
-rw-r--r--gcc/testsuite/g++.dg/cpp/warning-directive-2.C4
-rw-r--r--gcc/testsuite/g++.dg/cpp/warning-directive-3.C4
-rw-r--r--gcc/testsuite/g++.dg/cpp/warning-directive-4.C4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-comments-2.c7
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-comments.c7
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-cxx-compat-2.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-cxx-compat.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-deprecated-2.c7
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-deprecated.c7
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-long-long-2.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-long-long.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-multichar-2.c5
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-multichar.c5
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-normalized-1.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-normalized-2.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-normalized-3.c5
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-redefined-2.c18
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-redefined.c18
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-traditional-2.c23
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-traditional.c23
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-trigraphs-1.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-trigraphs-2.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-trigraphs-3.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-trigraphs-4.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-undef-2.c5
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-undef.c5
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-unused-macros-2.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-unused-macros.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-variadic-2.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warn-variadic.c6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warning-directive-1.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warning-directive-2.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warning-directive-3.c4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/warning-directive-4.c4
-rw-r--r--gcc/testsuite/gfortran.dg/warning-directive-1.F905
-rw-r--r--gcc/testsuite/gfortran.dg/warning-directive-2.F905
-rw-r--r--gcc/testsuite/gfortran.dg/warning-directive-3.F905
-rw-r--r--gcc/testsuite/gfortran.dg/warning-directive-4.F905
51 files changed, 507 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 693d69de50a..2a6c5938422 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,25 @@
+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>
* ipa-reference.c (mark_load): Use get_base_address.
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 66034a97a86..7daba6bfea1 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -8253,8 +8253,52 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
#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
- 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
should be used instead, with column number possibly overridden by
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,
otherwise. */
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,
const char *msg, va_list *ap)
{
@@ -8309,6 +8353,8 @@ c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level,
location, dlevel);
if (column_override)
diagnostic_override_column (&diagnostic, column_override);
+ diagnostic_override_option_index (&diagnostic,
+ c_option_controlling_cpp_error (reason));
ret = report_diagnostic (&diagnostic);
if (level == CPP_DL_WARNING_SYSHDR)
warn_system_headers = save_warn_system_headers;
diff --git a/gcc/c-opts.c b/gcc/c-opts.c
index 9d5fa2ea19a..a680f2d79bd 100644
--- a/gcc/c-opts.c
+++ b/gcc/c-opts.c
@@ -196,6 +196,90 @@ defer_opt (enum opt_code code, const char *arg)
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. */
unsigned int
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;
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
ends used to do it. Maybe this should be unconditional? */
if (c_dialect_cxx ())
diff --git a/gcc/c-tree.h b/gcc/c-tree.h
index 2309d51d589..dab9d39175e 100644
--- a/gcc/c-tree.h
+++ b/gcc/c-tree.h
@@ -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_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 *)
- ATTRIBUTE_GCC_CDIAG(5,0);
+ ATTRIBUTE_GCC_CDIAG(6,0);
#endif /* ! GCC_C_TREE_H */
diff --git a/gcc/common.opt b/gcc/common.opt
index 2b8b6d70620..49eb453f2a7 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -89,6 +89,10 @@ Wcast-align
Common Var(warn_cast_align) Warning
Warn about pointer casts which increase alignment
+Wcpp
+Common Var(warn_cpp) Init(1) Warning
+Warn when a #warning directive is encountered
+
Wdeprecated-declarations
Common Var(warn_deprecated_decl) Init(1) Warning
Warn about uses of __attribute__((deprecated)) declarations
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 78c19e92f64..de76477baa7 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -199,6 +199,11 @@ extern diagnostic_context *global_dc;
diagnostic. */
#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. */
extern void diagnostic_initialize (diagnostic_context *);
extern void diagnostic_report_current_module (diagnostic_context *);
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 76c424024e0..d356daaf021 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -232,7 +232,7 @@ Objective-C and Objective-C++ Dialects}.
-Wno-attributes -Wno-builtin-macro-redefined @gol
-Wc++-compat -Wc++0x-compat -Wcast-align -Wcast-qual @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-div-by-zero -Wempty-body -Wenum-compare -Wno-endif-labels @gol
-Werror -Werror=* @gol
@@ -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.
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
@opindex Wformat
@opindex Wno-format
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 2b1aa30b407..6502b89757d 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+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>
* options.c (gfc_init_options): Do not set.
diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c
index ec8bb59504c..6ff464a8cf0 100644
--- a/gcc/fortran/cpp.c
+++ b/gcc/fortran/cpp.c
@@ -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_used_define (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 *)
- ATTRIBUTE_GCC_DIAG(5,0);
+ ATTRIBUTE_GCC_DIAG(6,0);
void pp_dir_change (cpp_reader *, const char *);
static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
@@ -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
- 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
if not zero; MSG is the translated message and AP the arguments.
Returns true if a diagnostic was emitted, false otherwise. */
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,
const char *msg, va_list *ap)
{
@@ -1007,6 +1008,8 @@ cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level,
location, dlevel);
if (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);
if (level == CPP_DL_WARNING_SYSHDR)
warn_system_headers = save_warn_system_headers;
@@ -1090,5 +1093,3 @@ dump_queued_macros (cpp_reader *pfile ATTRIBUTE_UNUSED)
}
cpp_undefine_queue = NULL;
}
-
-
diff --git a/gcc/opts.c b/gcc/opts.c
index 7c928bb4c03..19d56348e2e 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -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
also by legacy Werror-implicit-function-declaration. */
@@ -2415,14 +2429,20 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask)
}
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);
+ 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 (cl_options[option_index].var_type == CLVC_BOOLEAN
- && cl_options[option_index].flag_var
- && kind == DK_ERROR)
- *(int *) cl_options[option_index].flag_var = 1;
+ if (warning_as_error_callback)
+ warning_as_error_callback (option_index);
+ }
}
free (new_option);
}
diff --git a/gcc/opts.h b/gcc/opts.h
index a2eef1938c7..54f57d114a3 100644
--- a/gcc/opts.h
+++ b/gcc/opts.h
@@ -105,6 +105,7 @@ extern int option_enabled (int opt_idx);
extern bool get_option_state (int, struct cl_option_state *);
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,
unsigned int lang_mask);
extern void print_ignored_options (void);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a074ef23d7c..81684784874 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,47 @@
-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.
2010-04-07 Jason Merrill <jason@redhat.com>
diff --git a/gcc/testsuite/g++.dg/cpp/warning-directive-1.C b/gcc/testsuite/g++.dg/cpp/warning-directive-1.C
new file mode 100644
index 00000000000..1ce18c6e2c6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/warning-directive-1.C
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-fdiagnostics-show-option" }
+
+#warning "Printed" // { dg-warning "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/g++.dg/cpp/warning-directive-2.C b/gcc/testsuite/g++.dg/cpp/warning-directive-2.C
new file mode 100644
index 00000000000..abd6427cd8a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/warning-directive-2.C
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-fdiagnostics-show-option -Werror=cpp" }
+
+#warning "Printed" // { dg-error "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/g++.dg/cpp/warning-directive-3.C b/gcc/testsuite/g++.dg/cpp/warning-directive-3.C
new file mode 100644
index 00000000000..8ed66c66f1d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/warning-directive-3.C
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-fdiagnostics-show-option -Werror -Wno-error=cpp" }
+
+#warning "Printed" // { dg-warning "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/g++.dg/cpp/warning-directive-4.C b/gcc/testsuite/g++.dg/cpp/warning-directive-4.C
new file mode 100644
index 00000000000..a5db1b4d5cd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/warning-directive-4.C
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-fdiagnostics-show-option -Wno-cpp" }
+
+#warning "Not printed" // { dg-bogus "." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-comments-2.c b/gcc/testsuite/gcc.dg/cpp/warn-comments-2.c
new file mode 100644
index 00000000000..5a17f2bdcf2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-comments-2.c
@@ -0,0 +1,7 @@
+// { 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 }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-comments.c b/gcc/testsuite/gcc.dg/cpp/warn-comments.c
new file mode 100644
index 00000000000..6f3d5a56fa7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-comments.c
@@ -0,0 +1,7 @@
+// { 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 }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-cxx-compat-2.c b/gcc/testsuite/gcc.dg/cpp/warn-cxx-compat-2.c
new file mode 100644
index 00000000000..6bf7d555e14
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-cxx-compat-2.c
@@ -0,0 +1,4 @@
+// { 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." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-cxx-compat.c b/gcc/testsuite/gcc.dg/cpp/warn-cxx-compat.c
new file mode 100644
index 00000000000..2e7b2593235
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-cxx-compat.c
@@ -0,0 +1,4 @@
+// { 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." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-deprecated-2.c b/gcc/testsuite/gcc.dg/cpp/warn-deprecated-2.c
new file mode 100644
index 00000000000..b9cfffb9630
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-deprecated-2.c
@@ -0,0 +1,7 @@
+// { 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
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-deprecated.c b/gcc/testsuite/gcc.dg/cpp/warn-deprecated.c
new file mode 100644
index 00000000000..84214b1f8db
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-deprecated.c
@@ -0,0 +1,7 @@
+// { 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
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-long-long-2.c b/gcc/testsuite/gcc.dg/cpp/warn-long-long-2.c
new file mode 100644
index 00000000000..11eb5fb2666
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-long-long-2.c
@@ -0,0 +1,6 @@
+// { 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
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-long-long.c b/gcc/testsuite/gcc.dg/cpp/warn-long-long.c
new file mode 100644
index 00000000000..e86f9a6288d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-long-long.c
@@ -0,0 +1,6 @@
+// { 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
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-multichar-2.c b/gcc/testsuite/gcc.dg/cpp/warn-multichar-2.c
new file mode 100644
index 00000000000..31d33bb9bb8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-multichar-2.c
@@ -0,0 +1,5 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=multichar" }
+
+#if 'abc' // { dg-error "multi-character character constant .-Wmultichar." }
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-multichar.c b/gcc/testsuite/gcc.dg/cpp/warn-multichar.c
new file mode 100644
index 00000000000..f5b02dad479
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-multichar.c
@@ -0,0 +1,5 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wmultichar" }
+
+#if 'abc' // { dg-warning "multi-character character constant .-Wmultichar." }
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-normalized-1.c b/gcc/testsuite/gcc.dg/cpp/warn-normalized-1.c
new file mode 100644
index 00000000000..fe1c5753074
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-normalized-1.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -fextended-identifiers -Wnormalized=nfc" }
+
+\u0F43 // { dg-warning "`.U00000f43' is not in NFC .-Wnormalized=." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-normalized-2.c b/gcc/testsuite/gcc.dg/cpp/warn-normalized-2.c
new file mode 100644
index 00000000000..f1fb96833d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-normalized-2.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -fextended-identifiers -Wnormalized=nfkc" }
+
+\u00AA // { dg-warning "`.U000000aa' is not in NFKC .-Wnormalized=." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-normalized-3.c b/gcc/testsuite/gcc.dg/cpp/warn-normalized-3.c
new file mode 100644
index 00000000000..380c670b8af
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-normalized-3.c
@@ -0,0 +1,5 @@
+// { 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=." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-redefined-2.c b/gcc/testsuite/gcc.dg/cpp/warn-redefined-2.c
new file mode 100644
index 00000000000..83cc3df7610
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-redefined-2.c
@@ -0,0 +1,18 @@
+// { 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 }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-redefined.c b/gcc/testsuite/gcc.dg/cpp/warn-redefined.c
new file mode 100644
index 00000000000..1d3e7fc3ed3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-redefined.c
@@ -0,0 +1,18 @@
+// { 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 }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-traditional-2.c b/gcc/testsuite/gcc.dg/cpp/warn-traditional-2.c
new file mode 100644
index 00000000000..cb5f690ccf7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-traditional-2.c
@@ -0,0 +1,23 @@
+// { 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." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-traditional.c b/gcc/testsuite/gcc.dg/cpp/warn-traditional.c
new file mode 100644
index 00000000000..f72f6db69d5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-traditional.c
@@ -0,0 +1,23 @@
+// { 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." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-1.c b/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-1.c
new file mode 100644
index 00000000000..4f3779df221
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-1.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -trigraphs -Wtrigraphs" }
+
+??= // { dg-warning "trigraph \\?\\?= converted to # .-Wtrigraphs." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-2.c b/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-2.c
new file mode 100644
index 00000000000..ff87ae54951
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-2.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wtrigraphs" }
+
+??= // { dg-warning "trigraph \\?\\?= ignored, use -trigraphs to enable .-Wtrigraphs." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-3.c b/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-3.c
new file mode 100644
index 00000000000..a993e2a190c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-3.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -trigraphs -Werror=trigraphs" }
+
+??= // { dg-error "trigraph \\?\\?= converted to # .-Wtrigraphs." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-4.c b/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-4.c
new file mode 100644
index 00000000000..240ae0f2175
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-trigraphs-4.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=trigraphs" }
+
+??= // { dg-error "trigraph \\?\\?= ignored, use -trigraphs to enable .-Wtrigraphs." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-undef-2.c b/gcc/testsuite/gcc.dg/cpp/warn-undef-2.c
new file mode 100644
index 00000000000..4eb80e0e945
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-undef-2.c
@@ -0,0 +1,5 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=undef" }
+
+#if x // { dg-error "\"x\" is not defined .-Wundef." }
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-undef.c b/gcc/testsuite/gcc.dg/cpp/warn-undef.c
new file mode 100644
index 00000000000..dd4524d8136
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-undef.c
@@ -0,0 +1,5 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wundef" }
+
+#if x // { dg-warning "\"x\" is not defined .-Wundef." }
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-unused-macros-2.c b/gcc/testsuite/gcc.dg/cpp/warn-unused-macros-2.c
new file mode 100644
index 00000000000..58eeebfcdd9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-unused-macros-2.c
@@ -0,0 +1,4 @@
+// { 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." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-unused-macros.c b/gcc/testsuite/gcc.dg/cpp/warn-unused-macros.c
new file mode 100644
index 00000000000..e1ce94eeee6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-unused-macros.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wunused-macros" }
+
+#define X X // { dg-warning "macro \"X\" is not used .-Wunused-macros." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-variadic-2.c b/gcc/testsuite/gcc.dg/cpp/warn-variadic-2.c
new file mode 100644
index 00000000000..f43d96ab81b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-variadic-2.c
@@ -0,0 +1,6 @@
+/* { 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." } */
diff --git a/gcc/testsuite/gcc.dg/cpp/warn-variadic.c b/gcc/testsuite/gcc.dg/cpp/warn-variadic.c
new file mode 100644
index 00000000000..ba66c901813
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warn-variadic.c
@@ -0,0 +1,6 @@
+/* { 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." } */
diff --git a/gcc/testsuite/gcc.dg/cpp/warning-directive-1.c b/gcc/testsuite/gcc.dg/cpp/warning-directive-1.c
new file mode 100644
index 00000000000..cb4bd326cc2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warning-directive-1.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option" }
+
+#warning "Printed" // { dg-warning "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warning-directive-2.c b/gcc/testsuite/gcc.dg/cpp/warning-directive-2.c
new file mode 100644
index 00000000000..0889803cd11
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warning-directive-2.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=cpp" }
+
+#warning "Printed" // { dg-error "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warning-directive-3.c b/gcc/testsuite/gcc.dg/cpp/warning-directive-3.c
new file mode 100644
index 00000000000..48c97f3ac5b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warning-directive-3.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror -Wno-error=cpp" }
+
+#warning "Printed" // { dg-warning "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warning-directive-4.c b/gcc/testsuite/gcc.dg/cpp/warning-directive-4.c
new file mode 100644
index 00000000000..2eb101765da
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/warning-directive-4.c
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wno-cpp" }
+
+#warning "Not printed" // { dg-bogus "." }
diff --git a/gcc/testsuite/gfortran.dg/warning-directive-1.F90 b/gcc/testsuite/gfortran.dg/warning-directive-1.F90
new file mode 100644
index 00000000000..5f5931572c2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/warning-directive-1.F90
@@ -0,0 +1,5 @@
+! { dg-do preprocess }
+! { dg-options "-std=f95 -fdiagnostics-show-option" }
+
+#warning "Printed"
+! { dg-warning "\"Printed\" .-Wcpp." "" { target *-*-* } 4 }
diff --git a/gcc/testsuite/gfortran.dg/warning-directive-2.F90 b/gcc/testsuite/gfortran.dg/warning-directive-2.F90
new file mode 100644
index 00000000000..75b78bf6dd9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/warning-directive-2.F90
@@ -0,0 +1,5 @@
+! { dg-do preprocess }
+! { dg-options "-std=f95 -fdiagnostics-show-option -Werror=cpp" }
+
+#warning "Printed"
+! { dg-error "\"Printed\" .-Wcpp." "" { target *-*-* } 4 }
diff --git a/gcc/testsuite/gfortran.dg/warning-directive-3.F90 b/gcc/testsuite/gfortran.dg/warning-directive-3.F90
new file mode 100644
index 00000000000..aa20c1942a1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/warning-directive-3.F90
@@ -0,0 +1,5 @@
+! { dg-do preprocess }
+! { dg-options "-std=f95 -fdiagnostics-show-option -Werror -Wno-error=cpp" }
+
+#warning "Printed"
+! { dg-warning "\"Printed\" .-Wcpp." "" { target *-*-* } 4 }
diff --git a/gcc/testsuite/gfortran.dg/warning-directive-4.F90 b/gcc/testsuite/gfortran.dg/warning-directive-4.F90
new file mode 100644
index 00000000000..a5c38114957
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/warning-directive-4.F90
@@ -0,0 +1,5 @@
+! { dg-do preprocess }
+! { dg-options "-std=f95 -fdiagnostics-show-option -Wno-cpp" }
+
+#warning "Not printed"
+! { dg-bogus "." "" { target *-*-* } 4 }