Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Andrew Burgess <andrew.burgess@embecosm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/3] Use type_instance_flags more throughout
Date: Mon, 14 Sep 2020 14:53:07 +0100	[thread overview]
Message-ID: <4c27500f-18b8-015e-0d89-9f18d652c872@palves.net> (raw)
In-Reply-To: <20200826152109.GV853475@embecosm.com>

On 8/26/20 4:21 PM, Andrew Burgess wrote:

>> diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
>> index 55a6dafb7e..b42cef6137 100644
>> --- a/gdb/gdbtypes.h
>> +++ b/gdb/gdbtypes.h
>> @@ -1585,7 +1585,10 @@ extern void allocate_gnat_aux_type (struct type *);
>>       TYPE_ZALLOC (type,							       \
>>  		  sizeof (*TYPE_MAIN_TYPE (type)->type_specific.func_stuff)))
>>  
>> -#define TYPE_INSTANCE_FLAGS(thistype) (thistype)->instance_flags
>> +#define TYPE_INSTANCE_FLAGS(thistype) \
>> +  type_instance_flags ((enum type_instance_flag_value) (thistype)->instance_flags)
>> +#define SET_TYPE_INSTANCE_FLAGS(thistype, flags) \
>> +  (thistype)->instance_flags = flags
> 
> There are some places where you've not updated a use of
> TYPE_INSTANCE_FLAGS.  The patch below fixes these.  In order to find
> these I changed TYPE_INSTANCE_FLAGS to make use of a member function
> returning a 'const type_instance_flags'.
> 
> Feel free to take any parts of this patch you think are useful.

Wow, these shouldn't even compile.  That is showing a hole in enum_flags.

>  
> -  TYPE_INSTANCE_FLAGS (builtin_d_type->builtin_byte)
> -    |= TYPE_INSTANCE_FLAG_NOTTEXT;

TYPE_INSTANCE_FLAGS does a cast, so this is the equivalent of:

  int flags = 0;
  (int) flags |= 1;

which of course doesn't compile:

 test.c:1:18: error: lvalue required as left operand of assignment
   1 |   (int) flags |= 1;
     |                  ^

I'm merging the patch below into the main enum flags patch, to
disable the rvalue versions of compound assignment.  It catches the
spots you caught as well:

 src/gdb/d-lang.c: In function ‘void* build_d_types(gdbarch*)’:
 src/gdb/d-lang.c:325:8: error: use of deleted function ‘void enum_flags<E>::operator|=(enum_flags<E>) && [with E = type_instance_flag_value]’
   325 |     |= TYPE_INSTANCE_FLAG_NOTTEXT;
       |        ^~~~~~~~~~~~~~~~~~~~~~~~~~

 src/gdb/ft32-tdep.c: In function ‘gdbarch* ft32_gdbarch_init(gdbarch_info, gdbarch_list*)’:
 src/gdb/ft32-tdep.c:580:42: error: use of deleted function ‘void enum_flags<E>::operator|=(enum_flags<E>) && [with E = type_instance_flag_value]’
   580 |   TYPE_INSTANCE_FLAGS (tdep->pc_type) |= TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
       |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'll merge your changes into the type_instance_flags patch.

From aadb29540a43d96dc234d0d8126e5081926eec02 Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Mon, 14 Sep 2020 14:48:34 +0100
Subject: [PATCH] delete rval

---
 gdb/unittests/enum-flags-selftests.c | 18 +++++++++---------
 gdbsupport/enum-flags.h              | 18 +++++++++++-------
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/gdb/unittests/enum-flags-selftests.c b/gdb/unittests/enum-flags-selftests.c
index 17ab5c9b09..af585f04ae 100644
--- a/gdb/unittests/enum-flags-selftests.c
+++ b/gdb/unittests/enum-flags-selftests.c
@@ -174,9 +174,9 @@ CHECK_VALID (true,  EF,   EF () ^ RE ())
 CHECK_VALID (false, void, RE () |= RE2 ())
 CHECK_VALID (false, void, RE () &= RE2 ())
 CHECK_VALID (false, void, RE () ^= RE2 ())
-CHECK_VALID (true,  RE&,  RE () |= RE ())
-CHECK_VALID (true,  RE&,  RE () &= RE ())
-CHECK_VALID (true,  RE&,  RE () ^= RE ())
+CHECK_VALID (false, void, RE () |= RE ())
+CHECK_VALID (false, void, RE () &= RE ())
+CHECK_VALID (false, void, RE () ^= RE ())
 
 /* operator OP= (raw_enum, raw_enum), lvalue ref on the lhs. */
 
@@ -192,9 +192,9 @@ CHECK_VALID (true,  RE&,  re ^= RE ())
 CHECK_VALID (false, void, EF () |= RE2 ())
 CHECK_VALID (false, void, EF () &= RE2 ())
 CHECK_VALID (false, void, EF () ^= RE2 ())
-CHECK_VALID (true,  EF&,  EF () |= RE ())
-CHECK_VALID (true,  EF&,  EF () &= RE ())
-CHECK_VALID (true,  EF&,  EF () ^= RE ())
+CHECK_VALID (false, void, EF () |= RE ())
+CHECK_VALID (false, void, EF () &= RE ())
+CHECK_VALID (false, void, EF () ^= RE ())
 
 /* operator OP= (enum_flags, raw_enum), lvalue ref on the lhs.  */
 
@@ -210,9 +210,9 @@ CHECK_VALID (true,  EF&,  ef ^= EF ())
 CHECK_VALID (false, void, EF () |= EF2 ())
 CHECK_VALID (false, void, EF () &= EF2 ())
 CHECK_VALID (false, void, EF () ^= EF2 ())
-CHECK_VALID (true,  EF&,  EF () |= EF ())
-CHECK_VALID (true,  EF&,  EF () &= EF ())
-CHECK_VALID (true,  EF&,  EF () ^= EF ())
+CHECK_VALID (false, void, EF () |= EF ())
+CHECK_VALID (false, void, EF () &= EF ())
+CHECK_VALID (false, void, EF () ^= EF ())
 
 /* operator OP= (enum_flags, enum_flags), lvalue ref on the lhs.  */
 
diff --git a/gdbsupport/enum-flags.h b/gdbsupport/enum-flags.h
index b3e317ecb9..d30d90b68d 100644
--- a/gdbsupport/enum-flags.h
+++ b/gdbsupport/enum-flags.h
@@ -147,22 +147,27 @@ class enum_flags
     : m_enum_value ((enum_type) 0)
   {}
 
-  enum_flags &operator&= (enum_flags e)
+  enum_flags &operator&= (enum_flags e) &
   {
     m_enum_value = (enum_type) (m_enum_value & e.m_enum_value);
     return *this;
   }
-  enum_flags &operator|= (enum_flags e)
+  enum_flags &operator|= (enum_flags e) &
   {
     m_enum_value = (enum_type) (m_enum_value | e.m_enum_value);
     return *this;
   }
-  enum_flags &operator^= (enum_flags e)
+  enum_flags &operator^= (enum_flags e) &
   {
     m_enum_value = (enum_type) (m_enum_value ^ e.m_enum_value);
     return *this;
   }
 
+  /* Delete rval versions.  */
+  void operator&= (enum_flags e) && = delete;
+  void operator|= (enum_flags e) && = delete;
+  void operator^= (enum_flags e) && = delete;
+
   /* Like raw enums, allow conversion to the underlying type.  */
   constexpr operator underlying_type () const
   {
@@ -278,9 +283,8 @@ using is_enum_flags_enum_type_t
   /* rval reference version.  */					\
   template <typename enum_type,						\
 	    typename = is_enum_flags_enum_type_t<enum_type>>		\
-  constexpr enum_type &							\
-  OPERATOR_OP (enum_type &&e1, enum_type e2)				\
-  { return e1 = e1 OP e2; }						\
+  void									\
+  OPERATOR_OP (enum_type &&e1, enum_type e2) = delete;			\
 									\
   /* Delete compound assignment from unrelated types.  */		\
 									\
@@ -291,7 +295,7 @@ using is_enum_flags_enum_type_t
 									\
   template <typename enum_type, typename other_enum_type,		\
 	    typename = is_enum_flags_enum_type_t<enum_type>>		\
-  constexpr enum_type &							\
+  void									\
   OPERATOR_OP (enum_type &&e1, other_enum_type e2) = delete;
 
 ENUM_FLAGS_GEN_BINOP (operator|, |)

-- 
2.14.5



  reply	other threads:[~2020-09-14 13:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21 14:45 [PATCH 0/3] Rewrite enum_flags, add unit tests, fix problems Pedro Alves
2020-08-21 14:45 ` [PATCH 1/3] Rewrite valid-expr.h's internals in terms of the detection idiom (C++17/N4502) Pedro Alves
2020-09-28 18:59   ` Tom Tromey
2020-09-28 19:58     ` Luis Machado via Gdb-patches
2020-09-28 20:00       ` Tom Tromey
2020-09-29 13:04         ` Tom Tromey
2020-09-29 19:24           ` Pedro Alves
2020-09-29 22:50             ` [pushed] Tweak gdbsupport/valid-expr.h for GCC 6, fix build (Re: [PATCH 1/3] Rewrite valid-expr.h's internals in terms of the detection idiom (C++17/N4502)) Pedro Alves
2020-08-21 14:45 ` [PATCH 2/3] Use type_instance_flags more throughout Pedro Alves
2020-08-25 11:36   ` Luis Machado
2020-09-14 11:56     ` Pedro Alves
2020-08-26 10:06   ` Andrew Burgess
2020-09-14 12:54     ` Pedro Alves
2020-08-26 15:21   ` Andrew Burgess
2020-09-14 13:53     ` Pedro Alves [this message]
2020-09-11 20:21   ` Tom Tromey
2020-09-14 19:26     ` Pedro Alves
2020-08-21 14:45 ` [PATCH 3/3] Rewrite enum_flags, add unit tests, fix problems Pedro Alves
2020-08-21 15:51 ` [PATCH 0/3] " Andrew Burgess
2020-09-11 20:26   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4c27500f-18b8-015e-0d89-9f18d652c872@palves.net \
    --to=pedro@palves.net \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox