public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH 3/3] gdb: handle default argument in make-target-delegates.py
Date: Tue, 14 Nov 2023 11:31:08 +0000	[thread overview]
Message-ID: <761454b8-0df3-4291-bc83-3fca7852c4ce@palves.net> (raw)
In-Reply-To: <476f2068afadd0d56827493eb014a90b41eea887.1699953637.git.tankut.baris.aktemur@intel.com>

On 2023-11-14 09:41, Tankut Baris Aktemur wrote:

> Currently, target.h does not contain any arguments with default
> values.  The goal of this patch is to address potential future and
> downstream cases; we (Intel) have cases with default argument values.

Hmm, but default arguments in virtual methods is generally considered a bad idea,
because default arguments are a static property which doesn't propagate when
you override a method.  Like:

#include <stdio.h>

struct A
{
  virtual void func (int arg = 1) { printf ("%d\n", arg); }
};

struct B : A
{
  virtual void func (int arg = 2) { printf ("%d\n", arg); }
};

struct C : A
{
  virtual void func (int arg) { printf ("%d\n", arg); }
};

int
main ()
{
   B *b = new B ();
   A *a = b;
   a->func ();  // prints "1".
   b->func ();  // prints "2".

   C *c = new C ();
   c->func ();  // doesn't even compile.
}

Instead, it's better practice to put the default argument in a non-virtual method that
then calls the virtual method.  We don't have those in target_ops, but we have instead
the global target_foo wrapper functions.  So instead of putting the default argument here:

 -   virtual void rcmd (const char *command=0, struct ui_file *output)
 +   virtual void rcmd (const char *command=0, struct ui_file *output = nullptr)
       TARGET_DEFAULT_FUNC (default_rcmd);

You should put the default here:

 -extern void target_rcmd (const char *command, struct ui_file *outbuf);
 +extern void target_rcmd (const char *command, struct ui_file *outbuf = nullptr);


  reply	other threads:[~2023-11-14 11:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14  9:41 [PATCH 1/3] gdb: regenerate target-delegates.c Tankut Baris Aktemur
2023-11-14  9:41 ` [PATCH 2/3] gdb: refactor make-target-delegates.py's ARGTYPES Tankut Baris Aktemur
2023-11-14 13:47   ` Pedro Alves
2023-11-14  9:41 ` [PATCH 3/3] gdb: handle default argument in make-target-delegates.py Tankut Baris Aktemur
2023-11-14 11:31   ` Pedro Alves [this message]
2023-11-14 12:48     ` Aktemur, Tankut Baris
2023-11-14 13:36       ` Pedro Alves
2023-11-14 14:17     ` Tom Tromey
2023-11-16 18:11       ` Aktemur, Tankut Baris
2023-11-17 15:41         ` Tom Tromey
2023-11-14 11:14 ` [PATCH 1/3] gdb: regenerate target-delegates.c Pedro Alves
2023-11-14 14:18 ` 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=761454b8-0df3-4291-bc83-3fca7852c4ce@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=tankut.baris.aktemur@intel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).