From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, Simon Marchi <simon.marchi@efficios.com>
Cc: gcc-patches@sourceware.org, gdb-patches@sourceware.org
Subject: Re: [PATCH 5/6] gdbsupport/selftest: print operand values when a SELF_CHECK fails
Date: Tue, 27 Oct 2026 13:06:29 -0400 [thread overview]
Message-ID: <0b939e47-36e7-4de4-883f-63aa39586ea1@simark.ca> (raw)
In-Reply-To: <87qzhbp6xy.fsf@tromey.com>
On 10/27/26 10:13 AM, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
>
> Simon> Some previously used constructs are now rejected at compile time, and
> Simon> require a few changes in the tests:
>
> Simon> - A top-level && or ||.
>
> I think this approach is very clever but I'm not really a fan of the result.
> It seems completely reasonable to me to want to write || or && in a test.
If you really need it (you only really "need" it for ||), you can always
add extra parentheses.
> Simon> - A lone non-bool value, like SELF_CHECK (ptr).
>
> This isn't really that weird either.
We could make it work, I just chose not to because of our coding style.
> Simon> Operands are printed using a value_to_string function that is a long
> Simon> series of "if constexpr" to print various types of operands. It ends
> Simon> with an always-false static_assert, such that trying to print an
> Simon> unsupported type will cause a build failure, and will require telling
> Simon> the function how to print said type.
>
> Why this way and not overloads?
I guess you mean templates with SFINAE to select the right printer? If
so: because it's easier to understand than separate templated functions,
especially the order in which rules are applied. With templates, you
have to know the template deduction rules, which isn't obvious. With a
single function, the decision tree is right there, easy to follow.
> It seems to me that the drawback of this approach is that now the test
> framework has to have visibility on every possible thing that could be
> printed.
We can abstract it somewhat by having the test framework just call
`val.to_string()` or `to_string(val)`, and then the specific `to_string`
implementations are not known by the test framework.
Simon
next prev parent reply other threads:[~2026-10-27 17:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 16:58 [PATCH 0/6] Make SELF_CHECK print operands of comparisons Simon Marchi
2026-10-19 16:58 ` [PATCH 1/6] gdb/unittests: catch gdb_exception_error in scoped_mmap test Simon Marchi
2026-10-19 16:58 ` [PATCH 2/6] gdbsupport/selftest: print expression when selftest fails and re-format Simon Marchi
2026-10-19 16:58 ` [PATCH 3/6] include/diagnostics.h: add DIAGNOSTIC_IGNORE_PARENTHESES Simon Marchi
2026-10-19 16:58 ` [PATCH 4/6] gdb/gmp-utils: rename gdb_mp{z,q,f}::str to to_string Simon Marchi
2026-10-19 16:58 ` [PATCH 5/6] gdbsupport/selftest: print operand values when a SELF_CHECK fails Simon Marchi
2026-10-27 14:13 ` Tom Tromey
2026-10-27 17:06 ` Simon Marchi [this message]
2026-10-19 16:58 ` [PATCH 6/6] gdb: remove manual printing of values in some selftests Simon Marchi
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=0b939e47-36e7-4de4-883f-63aa39586ea1@simark.ca \
--to=simark@simark.ca \
--cc=gcc-patches@sourceware.org \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
--cc=tom@tromey.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