Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Keith Seitz <keiths@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v2] Add infcall support for C++ constructor-style expressions
Date: Thu, 17 Sep 2026 16:10:38 +0100	[thread overview]
Message-ID: <875x03c3rl.fsf@redhat.com> (raw)
In-Reply-To: <b05ccda6e18b209f96401f7c4505b3a6690c5016.1777307103.git.keiths@redhat.com>

Keith Seitz <keiths@redhat.com> writes:

> Changes in v2:
> - Formatting fixes
> - Use c_isspace to skip whitespace in typename_token_for()
> - Merged rules for typename_for_ctor to type_exp
>   [This adds ~20 shift/reduce conflicts.]
> - Updated error message when overload-resolution is off
> - Handle static constructors and add new tests for this case
> - Added test case for when ctor is not found
> - Test early return: remove integer return status
>  
> Thanks,
> Keith
>
> ---------

I've only got trivial things to add over Kevin's existing review.

>
> This patch adds an initial try at teaching the expression parser/evaluator
> to construct temporary objects requiring construction during an inferior
> function call.
>
> To accomplish this, I've chosen the route of modifying the parser to
> teach it that `Type(args)' is a function call when `Type' names a
> class/struct/union and is immediately followed by '(', that is, via look-
> ahead). A new parser token and grammar rule have been added to deal
> with this new production.
>
> The real work is dispatched to `type_operation::evaluate_funcall',
> allocating memory for the temporary and finding the most suitable constructor
> with `find_overload_match'.  It then runs the inferior call, returning
> the newly constructed object.
>
> I've included many tests covering as many corner cases as I could invent,
> and these tests are clang clean.  They also introduce no regressions on
> x86-64 Fedora 43 with GCC 15.2.1 and RHEL 9.4 with GCC 11.5.0.
>
> Example:
> Consider a C++ frame where 'struct S { int x; S(int); ... }' is in scope
>
> Before:
> (gdb) print S(42)
> ❌️ A syntax error in expression, near `10)'.

I suspect a typo here, the error says '10', but the input is '42'.

> diff --git a/gdb/NEWS b/gdb/NEWS
> index e233906153a..24d26d29ea5 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -75,6 +75,11 @@
>  * The Windows native target now supports scheduler-locking.  E.g.,
>    "set scheduler-locking on" now works.  Previously it gave an error.
>  
> +* In C++ GDB now accepts constructor-style expressions "TYPE (ARGS)"

Need a command after 'In C++' here.

> diff --git a/gdb/eval.c b/gdb/eval.c
> index a00774bda3d..933415ce028 100644
> --- a/gdb/eval.c
> +++ b/gdb/eval.c
> @@ -1872,6 +1872,66 @@ type_operation::evaluate (struct type *expect_type, struct expression *exp,
>      error (_("Attempt to use a type name as an expression"));
>  }
>  
> +value *
> +type_operation::evaluate_funcall (struct type *expect_type,
> +				  struct expression *exp,
> +				  enum noside noside,
> +				  const std::vector<operation_up> &args)
> +{
> +  struct type *type = std::get<0> (m_storage);
> +  type = check_typedef (type);
> +
> +  /* Constructor-style call Type(args) is only for C++ aggregate types.  */
> +  gdb_assert (exp->language_defn->la_language == language_cplus);
> +
> +  const char *name = type->name ();
> +  if (name == nullptr)
> +    error (_("Cannot call constructor of unnamed type"));
> +
> +  /* Get the constructor name from the type name.  */
> +  gdb::unique_xmalloc_ptr<char> ctor_name_ptr = cp_func_name (name);
> +  const char *ctor_name =

This trailing '=' should be moved to the start of the next line.

Thanks,
Andrew


      parent reply	other threads:[~2026-09-17 15:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26 19:17 [PATCH] " Keith Seitz
2026-03-27  5:50 ` Eli Zaretskii
2026-04-21 13:41 ` Andrew Burgess
2026-04-21 18:13   ` Keith Seitz
2026-04-27 16:43 ` [PATCH v2] " Keith Seitz
2026-06-19 17:21   ` Keith Seitz
2026-06-27  0:06   ` Kevin Buettner
2026-07-29 17:44     ` Keith Seitz
2026-09-17 14:41       ` Andrew Burgess
2026-09-17 16:05         ` Keith Seitz
2026-09-17 15:10   ` Andrew Burgess [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=875x03c3rl.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@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