summaryrefslogtreecommitdiff
path: root/libcpp/init.c
diff options
context:
space:
mode:
authorOllie Wild <aaw@google.com>2012-04-27 14:29:32 +0000
committerOllie Wild <aaw@gcc.gnu.org>2012-04-27 14:29:32 +0000
commit7f5f5f98c5c21e263884362a248e5891e98ac6bc (patch)
tree4fb8c09994e5867bbbb9d8cd9a507399b19ac47e /libcpp/init.c
parent11ec770e46f664966c53b6af90a2849c1eb4dbd1 (diff)
downloadgcc-7f5f5f98c5c21e263884362a248e5891e98ac6bc.tar.gz
Add new option, -Wliteral-suffix.
This option, which is enabled by default, causes the preprocessor to warn when a string or character literal is followed by a ud-suffix which does not begin with an underscore. According to [lex.ext]p10, this is ill-formed. Also modifies the preprocessor to treat such ill-formed suffixes as separate preprocessing tokens. This is consistent with the Clang front end (see http://llvm.org/viewvc/llvm-project?view=rev&revision=152287), and enables backwards compatibility with code that uses formatting macros from <inttypes.h>, as in the following code block: int main() { int64_t i64 = 123; printf("My int64: %"PRId64"\n", i64); } Google ref b/6377711. 2012-04-27 Ollie Wild <aaw@google.com> PR c++/52538 * gcc/c-family/c-common.c: Add CPP_W_LITERAL_SUFFIX mapping. * gcc/c-family/c-opts.c (c_common_handle_option): Handle OPT_Wliteral_suffix. * gcc/c-family/c.opt: Add Wliteral-suffix. * gcc/doc/invoke.texi (Wliteral-suffix): Document new option. * gcc/testsuite/g++.dg/cpp0x/Wliteral-suffix.c: New test. * libcpp/include/cpplib.h (struct cpp_options): Add new field, warn_literal_suffix. (CPP_W_LITERAL_SUFFIX): New enum. * libcpp/init.c (cpp_create_reader): Default initialization of warn_literal_suffix. * libcpp/lex.c (lex_raw_string): Treat user-defined literals which don't begin with '_' as separate tokens and produce a warning. (lex_string): Ditto. From-SVN: r186909
Diffstat (limited to 'libcpp/init.c')
-rw-r--r--libcpp/init.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/libcpp/init.c b/libcpp/init.c
index 5fa82ca9c3e..3262184c9c5 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -175,6 +175,7 @@ cpp_create_reader (enum c_lang lang, hash_table *table,
CPP_OPTION (pfile, warn_variadic_macros) = 1;
CPP_OPTION (pfile, warn_builtin_macro_redefined) = 1;
CPP_OPTION (pfile, warn_normalize) = normalized_C;
+ CPP_OPTION (pfile, warn_literal_suffix) = 1;
/* Default CPP arithmetic to something sensible for the host for the
benefit of dumb users like fix-header. */