diff options
author | aaw <aaw@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-27 14:29:32 +0000 |
---|---|---|
committer | aaw <aaw@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-27 14:29:32 +0000 |
commit | 76d340ac07ad50937aa1ecbfdf0475b010a5700a (patch) | |
tree | 4fb8c09994e5867bbbb9d8cd9a507399b19ac47e /libcpp/include/cpplib.h | |
parent | c9f465998fbdc8b3fc70f668a792b183e2c40a47 (diff) |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186909 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp/include/cpplib.h')
-rw-r--r-- | libcpp/include/cpplib.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index bf59d016231d..9dbc477b61e8 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -427,6 +427,10 @@ struct cpp_options /* Nonzero for C++ 2011 Standard user-defnied literals. */ unsigned char user_literals; + /* Nonzero means warn when a string or character literal is followed by a + ud-suffix which does not beging with an underscore. */ + unsigned char warn_literal_suffix; + /* Holds the name of the target (execution) character set. */ const char *narrow_charset; @@ -906,7 +910,8 @@ enum { CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, - CPP_W_WARNING_DIRECTIVE + CPP_W_WARNING_DIRECTIVE, + CPP_W_LITERAL_SUFFIX }; /* Output a diagnostic of some kind. */ |