summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2017-12-01 15:19:07 -0500
committerJason Merrill <jason@gcc.gnu.org>2017-12-01 15:19:07 -0500
commitf2b8b8adbae9968ac30742498a21a92ac70523ff (patch)
tree2f9f105e39188cba5d4687ec6140a48fec7e11f9 /libcpp
parent0951904f491340404284480603f932bd551aec80 (diff)
downloadgcc-f2b8b8adbae9968ac30742498a21a92ac70523ff.tar.gz
PR c++/79228 - extensions hide C++14 complex literal operators
libcpp/ * expr.c (interpret_float_suffix): Ignore 'i' in C++14 and up. (interpret_int_suffix): Likewise. gcc/cp/ * parser.c (cp_parser_userdef_numeric_literal): Be helpful about 'i' in C++14 and up. From-SVN: r255335
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog6
-rw-r--r--libcpp/expr.c35
2 files changed, 37 insertions, 4 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 2250b7716d2..ec0492185f2 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,9 @@
+2017-12-01 Jason Merrill <jason@redhat.com>
+
+ PR c++/79228 - extensions hide C++14 complex literal operators
+ * expr.c (interpret_float_suffix): Ignore 'i' in C++14 and up.
+ (interpret_int_suffix): Likewise.
+
2017-11-28 David Malcolm <dmalcolm@redhat.com>
PR c/82050
diff --git a/libcpp/expr.c b/libcpp/expr.c
index 04675d8faee..fe9f6b0188c 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -90,6 +90,8 @@ static cpp_num parse_has_include (cpp_reader *, enum include_type);
static unsigned int
interpret_float_suffix (cpp_reader *pfile, const uchar *s, size_t len)
{
+ size_t orig_len = len;
+ const uchar *orig_s = s;
size_t flags;
size_t f, d, l, w, q, i, fn, fnx, fn_bits;
@@ -269,8 +271,20 @@ interpret_float_suffix (cpp_reader *pfile, const uchar *s, size_t len)
if (fn && fn_bits == 96)
return 0;
- if (i && !CPP_OPTION (pfile, ext_numeric_literals))
- return 0;
+ if (i)
+ {
+ if (!CPP_OPTION (pfile, ext_numeric_literals))
+ return 0;
+
+ /* In C++14 and up these suffixes are in the standard library, so treat
+ them as user-defined literals. */
+ if (CPP_OPTION (pfile, cplusplus)
+ && CPP_OPTION (pfile, lang) > CLK_CXX11
+ && (!memcmp (orig_s, "i", orig_len)
+ || !memcmp (orig_s, "if", orig_len)
+ || !memcmp (orig_s, "il", orig_len)))
+ return 0;
+ }
if ((w || q) && !CPP_OPTION (pfile, ext_numeric_literals))
return 0;
@@ -299,6 +313,7 @@ cpp_interpret_float_suffix (cpp_reader *pfile, const char *s, size_t len)
static unsigned int
interpret_int_suffix (cpp_reader *pfile, const uchar *s, size_t len)
{
+ size_t orig_len = len;
size_t u, l, i;
u = l = i = 0;
@@ -321,8 +336,20 @@ interpret_int_suffix (cpp_reader *pfile, const uchar *s, size_t len)
if (l > 2 || u > 1 || i > 1)
return 0;
- if (i && !CPP_OPTION (pfile, ext_numeric_literals))
- return 0;
+ if (i)
+ {
+ if (!CPP_OPTION (pfile, ext_numeric_literals))
+ return 0;
+
+ /* In C++14 and up these suffixes are in the standard library, so treat
+ them as user-defined literals. */
+ if (CPP_OPTION (pfile, cplusplus)
+ && CPP_OPTION (pfile, lang) > CLK_CXX11
+ && (!memcmp (s, "i", orig_len)
+ || !memcmp (s, "if", orig_len)
+ || !memcmp (s, "il", orig_len)))
+ return 0;
+ }
return ((i ? CPP_N_IMAGINARY : 0)
| (u ? CPP_N_UNSIGNED : 0)