Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Wielaard <mjw@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] implement support for "enum class"
Date: Fri, 28 Mar 2014 11:21:00 -0000	[thread overview]
Message-ID: <1396005664.3824.70.camel@bordewijk.wildebeest.org> (raw)
In-Reply-To: <1395951111-8189-1-git-send-email-tromey@redhat.com>

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


  reply	other threads:[~2014-03-28 11:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-27 20:12 Tom Tromey
2014-03-28 11:21 ` Mark Wielaard [this message]
2014-03-31  4:38   ` Tom Tromey
2014-03-31  7:16     ` Mark Wielaard
2014-03-31 18:19       ` Tom Tromey
2014-04-14 18:07         ` Tom Tromey
2014-05-21 14:04         ` Mark Wielaard
2014-05-21 14:25           ` 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=1396005664.3824.70.camel@bordewijk.wildebeest.org \
    --to=mjw@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /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