summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2014-08-10 06:10:49 +0000
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2014-08-10 06:10:49 +0000
commit890c2e2f1c0bc4461c6d606549394a536e386845 (patch)
treead84805c19739010caa9af61cb0d2c384e5aa852 /libcpp
parent25544eba8dcf50a87678709edc0c5e8414d759ed (diff)
downloadgcc-890c2e2f1c0bc4461c6d606549394a536e386845.tar.gz
PR c/51849
gcc/ * gcc/doc/invoke.texi: Document -Wc90-c99-compat. gcc/c-family/ * c-opts.c (sanitize_cpp_opts): Pass warn_c90_c99_compat to libcpp. * c.opt (Wc90-c99-compat): Add option. gcc/c/ * c-decl.c (build_array_declarator): Remove check for !flag_isoc99. Call pedwarn_c90 instead of pedwarn. (check_bitfield_type_and_width): Likewise. (declspecs_add_qual): Likewise. (declspecs_add_type): Likewise. (warn_variable_length_array): Unify function for -pedantic and -Wvla. Adjust to only call pedwarn_c90. (grokdeclarator): Remove pedantic && !flag_isoc99 check. Call pedwarn_c90 instead of pedwarn. * c-errors.c (pedwarn_c90): Handle -Wc90-c99-compat. * c-parser.c (disable_extension_diagnostics): Handle warn_c90_c99_compat. (restore_extension_diagnostics): Likewise. (c_parser_enum_specifier): Remove check for !flag_isoc99. Call pedwarn_c90 instead of pedwarn. (c_parser_initelt): Likewise. (c_parser_postfix_expression): Likewise. (c_parser_postfix_expression_after_paren_type): Likewise. (c_parser_compound_statement_nostart): Remove check for !flag_isoc99. * c-tree.h: Fix formatting. * c-typeck.c (build_array_ref): Remove check for !flag_isoc99. Call pedwarn_c90 instead of pedwarn. gcc/testsuite/ * gcc.dg/Wc90-c99-compat-1.c: New test. * gcc.dg/Wc90-c99-compat-2.c: New test. * gcc.dg/Wc90-c99-compat-3.c: New test. * gcc.dg/Wc90-c99-compat-4.c: New test. * gcc.dg/Wc90-c99-compat-5.c: New test. * gcc.dg/Wc90-c99-compat-6.c: New test. * gcc.dg/wvla-1.c: Adjust dg-warning. * gcc.dg/wvla-2.c: Adjust dg-warning. * gcc.dg/wvla-4.c: Adjust dg-warning. * gcc.dg/wvla-6.c: Adjust dg-warning. libcpp/ * lex.c (_cpp_lex_direct): Warn when -Wc90-c99-compat is in effect. * charset.c (_cpp_valid_ucn): Likewise. * include/cpplib.h (cpp_options): Add cpp_warn_c90_c99_compat. * macro.c (replace_args): Warn when -Wc90-c99-compat is in effect. (parse_params): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@213786 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog9
-rw-r--r--libcpp/charset.c4
-rw-r--r--libcpp/include/cpplib.h3
-rw-r--r--libcpp/lex.c12
-rw-r--r--libcpp/macro.c14
5 files changed, 41 insertions, 1 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index e550d177c26..54581dd3b67 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,12 @@
+2014-08-10 Marek Polacek <polacek@redhat.com>
+
+ PR c/51849
+ * lex.c (_cpp_lex_direct): Warn when -Wc90-c99-compat is in effect.
+ * charset.c (_cpp_valid_ucn): Likewise.
+ * include/cpplib.h (cpp_options): Add cpp_warn_c90_c99_compat.
+ * macro.c (replace_args): Warn when -Wc90-c99-compat is in effect.
+ (parse_params): Likewise.
+
2014-07-27 Marek Polacek <polacek@redhat.com>
PR c/61861
diff --git a/libcpp/charset.c b/libcpp/charset.c
index a3c24d68626..fa46f9226d7 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -995,6 +995,10 @@ _cpp_valid_ucn (cpp_reader *pfile, const uchar **pstr,
if (!CPP_OPTION (pfile, cplusplus) && !CPP_OPTION (pfile, c99))
cpp_error (pfile, CPP_DL_WARNING,
"universal character names are only valid in C++ and C99");
+ else if (CPP_OPTION (pfile, cpp_warn_c90_c99_compat)
+ && !CPP_OPTION (pfile, cplusplus))
+ cpp_error (pfile, CPP_DL_WARNING,
+ "C99's universal character names are incompatible with C90");
else if (CPP_WTRADITIONAL (pfile) && identifier_pos == 0)
cpp_warning (pfile, CPP_W_TRADITIONAL,
"the meaning of '\\%c' is different in traditional C",
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index a83452b9145..4cd66cdceaf 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -466,6 +466,9 @@ struct cpp_options
/* True if dependencies should be restored from a precompiled header. */
bool restore_pch_deps;
+ /* True if warn about differences between C90 and C99. */
+ bool cpp_warn_c90_c99_compat;
+
/* Dependency generation. */
struct
{
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 7e2db64db09..5cc2224329e 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -2325,7 +2325,7 @@ _cpp_lex_direct (cpp_reader *pfile)
else if (c == '/' && (CPP_OPTION (pfile, cplusplus_comments)
|| cpp_in_system_header (pfile)))
{
- /* Warn about comments only if pedantically GNUC89, and not
+ /* Warn about comments if pedantically GNUC89, and not
in system headers. */
if (CPP_OPTION (pfile, lang) == CLK_GNUC89 && CPP_PEDANTIC (pfile)
&& ! buffer->warned_cplusplus_comments)
@@ -2336,6 +2336,16 @@ _cpp_lex_direct (cpp_reader *pfile)
"(this will be reported only once per input file)");
buffer->warned_cplusplus_comments = 1;
}
+ /* Or if specifically desired via -Wc90-c99-compat. */
+ else if (CPP_OPTION (pfile, cpp_warn_c90_c99_compat)
+ && ! buffer->warned_cplusplus_comments)
+ {
+ cpp_error (pfile, CPP_DL_WARNING,
+ "C++ style comments are are incompatible with C90");
+ cpp_error (pfile, CPP_DL_WARNING,
+ "(this will be reported only once per input file)");
+ buffer->warned_cplusplus_comments = 1;
+ }
if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments))
cpp_warning (pfile, CPP_W_COMMENTS, "multi-line comment");
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 556628ba7c7..ff6685c2665 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -1795,6 +1795,16 @@ replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro,
NODE_NAME (node),
src->val.macro_arg.arg_no);
}
+ else if (CPP_OPTION (pfile, cpp_warn_c90_c99_compat)
+ && ! macro->syshdr
+ && ! cpp_in_system_header (pfile)
+ && ! CPP_OPTION (pfile, cplusplus))
+ cpp_error (pfile, CPP_DL_WARNING,
+ "invoking macro %s argument %d: "
+ "empty macro arguments are undefined"
+ " in ISO C90",
+ NODE_NAME (node),
+ src->val.macro_arg.arg_no);
/* Avoid paste on RHS (even case count == 0). */
if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
@@ -2848,6 +2858,10 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
(pfile, CPP_W_VARIADIC_MACROS,
"anonymous variadic macros were introduced in C99");
}
+ else if (CPP_OPTION (pfile, cpp_warn_c90_c99_compat)
+ && ! CPP_OPTION (pfile, cplusplus))
+ cpp_error (pfile, CPP_DL_WARNING,
+ "anonymous variadic macros were introduced in C99");
}
else if (CPP_OPTION (pfile, cpp_pedantic)
&& CPP_OPTION (pfile, warn_variadic_macros))