public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH][gdb/c++] Print destructor the same for gcc and clang
Date: Thu, 29 Sep 2022 21:01:58 +0100	[thread overview]
Message-ID: <506885b4-6ba7-6950-12ad-eae4afb0c543@palves.net> (raw)
In-Reply-To: <20220927103546.GA27362@delia.home>

On 2022-09-27 11:35 a.m., Tom de Vries wrote:

> 
> Note that I consider the discussion of whether we want to print:
> - A(void) / ~A(void), or
> - A() / ~A()
> out-of-scope for this patch.
> 

I'd vote to remove the void.  I can't think of a good reason to keep it (for C++).
It just looks odd to C++ developers, IMHO.

I'm fine with that being a separate decision from this patch, though.

> diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
> index 3a611cdac5d..23e8a5a4d6f 100644
> --- a/gdb/c-typeprint.c
> +++ b/gdb/c-typeprint.c
> @@ -273,35 +273,44 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
>  		  language_cplus, DMGL_ANSI);
>    gdb_puts ("(", stream);
>  
> -  /* Skip the class variable.  We keep this here to accommodate older
> -     compilers and debug formats which may not support artificial
> -     parameters.  */
> -  i = staticp ? 0 : 1;
> -  if (nargs > i)
> +  int printed_args = 0;
> +  for (i = 0; i < nargs; ++i)
>      {
> -      while (i < nargs)
> +      if (i == 0 && !staticp)
>  	{
> -	  struct field arg = args[i++];
> -
> -	  /* Skip any artificial arguments.  */
> -	  if (FIELD_ARTIFICIAL (arg))
> -	    continue;
> +	  /* Skip the class variable.  We keep this here to accommodate older
> +	     compilers and debug formats which may not support artificial
> +	     parameters.  */
> +	  continue;
> +	}


A remark on this preexisting "Skip the class variable." logic -- I strongly suspect that we'll
need to revisit it for the C++23 "deducing this" feature:

  https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0847r6.html

With that feature, some methods we'll have explicit, named "this" parameters, and
thus, I'd think, be non-artificial.  E.g., from the proposal:

 struct X {
     void foo(this X const& self, int i);
 
     template <typename Self>
     void bar(this Self&& self);
 };

Plainly skipping printing the "self" parameter in these methods just because it is a non-static
method, and "self" is the first parameter, will be incorrect.

According to:

  https://gcc.gnu.org/projects/cxx-status.html
  https://clang.llvm.org/cxx_status.html

neither GCC not Clang support that yet though.

We don't have tests for many of the C++14, C++17 and C++20 features, so I'm not holding my
breath waiting for tests for this, though.  :-P

> +++ b/gdb/testsuite/gdb.cp/print-method-args.exp
> @@ -0,0 +1,36 @@
> +# Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# This file is part of the gdb testsuite.
> +

Can you add an intro comment?  LGTM with that fixed.

      parent reply	other threads:[~2022-09-29 20:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27 10:35 Tom de Vries
2022-09-27 14:16 ` Bruno Larsen
2022-09-29 17:52 ` Keith Seitz
2022-09-29 20:03   ` Pedro Alves
2022-09-29 20:01 ` Pedro Alves [this message]

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=506885b4-6ba7-6950-12ad-eae4afb0c543@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).