aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog11
-rw-r--r--libcpp/include/cpplib.h7
-rw-r--r--libcpp/init.c1
-rw-r--r--libcpp/lex.c44
4 files changed, 56 insertions, 7 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 08878b2..f7c330c 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,14 @@
+2012-04-27 Ollie Wild <aaw@google.com>
+
+ * include/cpplib.h (struct cpp_options): Add new field,
+ warn_literal_suffix.
+ (CPP_W_LITERAL_SUFFIX): New enum.
+ * init.c (cpp_create_reader): Default initialization of
+ warn_literal_suffix.
+ * lex.c (lex_raw_string): Treat user-defined literals which don't
+ begin with '_' as separate tokens and produce a warning.
+ (lex_string): Ditto.
+
2012-04-26 Manuel López-Ibáñez <manu@gcc.gnu.org>
* line-map.c (linemap_resolve_location): Synchronize comments with
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index bf59d01..9dbc477 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. */
diff --git a/libcpp/init.c b/libcpp/init.c
index 5fa82ca..3262184 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. */
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 9d23002..7e2671e 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -1553,14 +1553,30 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base,
if (CPP_OPTION (pfile, user_literals))
{
+ /* According to C++11 [lex.ext]p10, a ud-suffix not starting with an
+ underscore is ill-formed. Since this breaks programs using macros
+ from inttypes.h, we generate a warning and treat the ud-suffix as a
+ separate preprocessing token. This approach is under discussion by
+ the standards committee, and has been adopted as a conforming
+ extension by other front ends such as clang. */
+ if (ISALPHA (*cur))
+ {
+ // Raise a warning, but do not consume subsequent tokens.
+ if (CPP_OPTION (pfile, warn_literal_suffix))
+ cpp_warning_with_line (pfile, CPP_W_LITERAL_SUFFIX,
+ token->src_loc, 0,
+ "invalid suffix on literal; C++11 requires "
+ "a space between literal and identifier");
+ }
/* Grab user defined literal suffix. */
- if (ISIDST (*cur))
+ else if (*cur == '_')
{
type = cpp_userdef_string_add_type (type);
++cur;
+
+ while (ISIDNUM (*cur))
+ ++cur;
}
- while (ISIDNUM (*cur))
- ++cur;
}
pfile->buffer->cur = cur;
@@ -1668,15 +1684,31 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base)
if (CPP_OPTION (pfile, user_literals))
{
+ /* According to C++11 [lex.ext]p10, a ud-suffix not starting with an
+ underscore is ill-formed. Since this breaks programs using macros
+ from inttypes.h, we generate a warning and treat the ud-suffix as a
+ separate preprocessing token. This approach is under discussion by
+ the standards committee, and has been adopted as a conforming
+ extension by other front ends such as clang. */
+ if (ISALPHA (*cur))
+ {
+ // Raise a warning, but do not consume subsequent tokens.
+ if (CPP_OPTION (pfile, warn_literal_suffix))
+ cpp_warning_with_line (pfile, CPP_W_LITERAL_SUFFIX,
+ token->src_loc, 0,
+ "invalid suffix on literal; C++11 requires "
+ "a space between literal and identifier");
+ }
/* Grab user defined literal suffix. */
- if (ISIDST (*cur))
+ else if (*cur == '_')
{
type = cpp_userdef_char_add_type (type);
type = cpp_userdef_string_add_type (type);
++cur;
+
+ while (ISIDNUM (*cur))
+ ++cur;
}
- while (ISIDNUM (*cur))
- ++cur;
}
pfile->buffer->cur = cur;