aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorThomas Schwinge <tschwinge@baylibre.com>2024-03-11 00:34:22 +0100
committerThomas Schwinge <tschwinge@baylibre.com>2024-03-11 00:34:22 +0100
commitafd1220e0ba653118b3699659e89c8bd35e1b722 (patch)
tree06868e63efee41c23c5d7261ab43e2a67767487c /libcpp
parentddbb4d3a4145bd5b05ca23dd5dfb562ecab1f512 (diff)
parent18c90eaa25363d34b5bef444fbbad04f5da2522d (diff)
downloadgcc-afd1220e0ba653118b3699659e89c8bd35e1b722.zip
gcc-afd1220e0ba653118b3699659e89c8bd35e1b722.tar.gz
gcc-afd1220e0ba653118b3699659e89c8bd35e1b722.tar.bz2
Merge commit '1ad5ae5a45f2e3fc6948b35a3b052fdd48453704^' into HEAD
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog12
-rw-r--r--libcpp/expr.cc52
-rw-r--r--libcpp/include/cpplib.h1
3 files changed, 61 insertions, 4 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 6197e49..9897dcf 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,15 @@
+2023-09-06 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/102989
+ * expr.cc (cpp_classify_number): Diagnose wb literal suffixes
+ for -pedantic* before C2X or -Wc11-c2x-compat.
+
+2023-09-06 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/102989
+ * expr.cc (interpret_int_suffix): Handle wb and WB suffixes.
+ * include/cpplib.h (CPP_N_BITINT): Define.
+
2023-08-07 Alan Modra <amodra@gmail.com>
* configure: Regenerate.
diff --git a/libcpp/expr.cc b/libcpp/expr.cc
index 6e5bf68e..338395a 100644
--- a/libcpp/expr.cc
+++ b/libcpp/expr.cc
@@ -327,9 +327,9 @@ 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, z;
+ size_t u, l, i, z, wb;
- u = l = i = z = 0;
+ u = l = i = z = wb = 0;
while (len--)
switch (s[len])
@@ -343,11 +343,23 @@ interpret_int_suffix (cpp_reader *pfile, const uchar *s, size_t len)
if (l == 2 && s[len] != s[len + 1])
return 0;
break;
+ case 'b':
+ if (len == 0 || s[len - 1] != 'w')
+ return 0;
+ wb++;
+ len--;
+ break;
+ case 'B':
+ if (len == 0 || s[len - 1] != 'W')
+ return 0;
+ wb++;
+ len--;
+ break;
default:
return 0;
}
- if (l > 2 || u > 1 || i > 1 || z > 1)
+ if (l > 2 || u > 1 || i > 1 || z > 1 || wb > 1)
return 0;
if (z)
@@ -358,6 +370,14 @@ interpret_int_suffix (cpp_reader *pfile, const uchar *s, size_t len)
return 0;
}
+ if (wb)
+ {
+ if (CPP_OPTION (pfile, cplusplus))
+ return 0;
+ if (l > 0 || i > 0 || z > 0)
+ return 0;
+ }
+
if (i)
{
if (!CPP_OPTION (pfile, ext_numeric_literals))
@@ -376,7 +396,8 @@ interpret_int_suffix (cpp_reader *pfile, const uchar *s, size_t len)
| (u ? CPP_N_UNSIGNED : 0)
| ((l == 0) ? CPP_N_SMALL
: (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE)
- | (z ? CPP_N_SIZE_T : 0));
+ | (z ? CPP_N_SIZE_T : 0)
+ | (wb ? CPP_N_BITINT : 0));
}
/* Return the classification flags for an int suffix. */
@@ -835,6 +856,29 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
virtual_location, 0, message);
}
+ if ((result & CPP_N_BITINT) != 0
+ && CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) != 0)
+ {
+ if (CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) > 0)
+ {
+ const char *message = N_("ISO C does not support literal "
+ "%<wb%> suffixes before C2X");
+ if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, true_false))
+ cpp_pedwarning_with_line (pfile, CPP_W_C11_C2X_COMPAT,
+ virtual_location, 0, message);
+ else
+ cpp_warning_with_line (pfile, CPP_W_C11_C2X_COMPAT,
+ virtual_location, 0, message);
+ }
+ else if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, true_false))
+ {
+ const char *message = N_("ISO C does not support literal "
+ "%<wb%> suffixes before C2X");
+ cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
+ message);
+ }
+ }
+
result |= CPP_N_INTEGER;
}
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 9f212a6..4ad75f8 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -1284,6 +1284,7 @@ struct cpp_num
#define CPP_N_SIZE_T 0x2000000 /* C++23 size_t literal. */
#define CPP_N_BFLOAT16 0x4000000 /* std::bfloat16_t type. */
+#define CPP_N_BITINT 0x8000000 /* C2X _BitInt literal. */
#define CPP_N_WIDTH_FLOATN_NX 0xF0000000 /* _FloatN / _FloatNx value
of N, divided by 16. */