On 4/21/21 2:15 AM, Martin Liška wrote:
Hello.
It's addressing the following Clang warning:
cp/lex.c:170:45: warning: result of comparison of constant 64 with expression
of type 'enum ovl_op_code' is always true
[-Wtautological-constant-out-of-range-compare]
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
gcc/cp/ChangeLog:
* cp-tree.h (STATIC_ASSERT): Prefer static assert.
* lex.c (init_operators): Remove run-time check.
---
gcc/cp/cp-tree.h | 3 +++
gcc/cp/lex.c | 2 --
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 81ff375f8a5..a8f72448ea9 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5916,6 +5916,9 @@ enum ovl_op_code {
OVL_OP_MAX
};
+/* Make sure it fits in lang_decl_fn::operator_code. */
+STATIC_ASSERT (OVL_OP_MAX < (1 << 6));
+
I wonder if there's a way to test this directly by something like
static_assert (number-of-bits (ovl_op_info_t::ovl_op_code)
<= number-of-bits (lang_decl_fn::operator_code));
Also, since we are now compiling in C++ 11 mode, would using
static_assert be appropriate?
Martin
struct GTY(()) ovl_op_info_t {
/* The IDENTIFIER_NODE for the operator. */
tree identifier;
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index 73e14b8394c..43abd019e6e 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -166,8 +166,6 @@ init_operators (void)
if (op_ptr->name)
{
- /* Make sure it fits in lang_decl_fn::operator_code. */
- gcc_checking_assert (op_ptr->ovl_op_code < (1 << 6));
tree ident = set_operator_ident (op_ptr);
if (unsigned index = IDENTIFIER_CP_INDEX (ident))
{