This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] implement support for "enum class"


On Thu, 2014-03-27 at 14:11 -0600, Tom Tromey wrote:
> This adds support for the C++11 "enum class" feature.  This is
> PR c++/15246.
> 
> I chose to use the existing TYPE_DECLARED_CLASS rather than introduce
> a new type code.  This seemed both simple and clear to me.
> 
> I made overloading support for the new enum types strict.  This is how
> it works in C++; and it didn't seem like an undue burden to keep this,
> particularly because enum constants are printed symbolically by gdb.
> 
> Built and regtested on x86-64 Fedora 20.
> [...]
> +gdb_test "ptype E1" \
> +    "type = enum class E1 {E1::HI = 7, E1::THERE}"

This FAILs for me with gcc plus
http://gcc.gnu.org/ml/gcc-patches/2014-03/msg01448.html
because it will derive:

Breakpoint 1, main () at /home/mark/src/binutils-gdb/gdb/testsuite/gdb.cp/enumclass.cc:45
45        return 0;
(gdb) ptype E1
type = enum class E1 : int {E1::HI = 7, E1::THERE}

Note the : int.

I think this comes from:

diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
> index 4edc9ec..04b6d7b 100644
> --- a/gdb/c-typeprint.c
> +++ b/gdb/c-typeprint.c
> [...]
> @@ -1349,6 +1351,14 @@ c_type_print_base (struct type *type, struct ui_file *stream,
>  	{
>  	  LONGEST lastval = 0;
>  
> +	  if (TYPE_TARGET_TYPE (type) != NULL)
> +	    {
> +	      struct type *underlying = check_typedef (TYPE_TARGET_TYPE (type));
> +
> +	      if (TYPE_NAME (underlying) != NULL)
> +		fprintf_filtered (stream, ": %s ", TYPE_NAME (underlying));
> +	    }
> +
>  	  fprintf_filtered (stream, "{");
>  	  len = TYPE_NFIELDS (type);
>  	  for (i = 0; i < len; i++)

If the test is right then I think you don't want to print the underlying
type if DW_AT_enum_class is set and the enum has type safe semantics?
Maybe:

diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 04b6d7b..299d859 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -1351,7 +1351,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
        {
          LONGEST lastval = 0;
 
-         if (TYPE_TARGET_TYPE (type) != NULL)
+         if (TYPE_TARGET_TYPE (type) != NULL && ! TYPE_DECLARED_CLASS (type))
            {
              struct type *underlying = check_typedef (TYPE_TARGET_TYPE (type));
 
Cheers,

Mark


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]