From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Jason Merrill <jason@redhat.com>
Cc: "Arsen Arsenović" <arsen@aarsen.me>,
gcc-patches@gcc.gnu.org, jwakely@redhat.com,
libstdc++@gcc.gnu.org
Subject: Re: [PATCH 1/3] libstdc++: Improve output of default contract violation handler [PR107792]
Date: Thu, 22 Dec 2022 22:02:07 +0000 [thread overview]
Message-ID: <CAH6eHdSCnJc-X7x5CESv7ZtwM1nRgzxivDaup3fy1R9K9YeArw@mail.gmail.com> (raw)
In-Reply-To: <3ebc61d5-f662-7064-8b03-d7689cd1bb4a@redhat.com>
On Thu, 22 Dec 2022 at 21:41, Jason Merrill via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> On 12/22/22 06:03, Arsen Arsenović wrote:
> > From: Jonathan Wakely <jwakely@redhat.com>
> >
> > Make the output more readable. Don't output anything unless verbose
> > termination is enabled at configure-time.
>
> LGTM if Jonathan agrees. The testsuite changes should be applied in the
> same commit.
Yup, Arsen and I have been discussing this patch over IRC, I'm happy with it.
>
> > libstdc++-v3/ChangeLog:
> >
> > PR libstdc++/107792
> > PR libstdc++/107778
> > * src/experimental/contract.cc (handle_contract_violation): Make
> > output more readable.
> > ---
> > Heh, wouldn't be me if I forgot nothing. Sorry about that.
> >
> > How's this?
> >
> > libstdc++-v3/src/experimental/contract.cc | 50 ++++++++++++++++++-----
> > 1 file changed, 39 insertions(+), 11 deletions(-)
> >
> > diff --git a/libstdc++-v3/src/experimental/contract.cc b/libstdc++-v3/src/experimental/contract.cc
> > index c8d2697eddc..2d41a6326cf 100644
> > --- a/libstdc++-v3/src/experimental/contract.cc
> > +++ b/libstdc++-v3/src/experimental/contract.cc
> > @@ -1,4 +1,5 @@
> > // -*- C++ -*- std::experimental::contract_violation and friends
> > +
> > // Copyright (C) 2019-2022 Free Software Foundation, Inc.
> > //
> > // This file is part of GCC.
> > @@ -23,19 +24,46 @@
> > // <http://www.gnu.org/licenses/>.
> >
> > #include <experimental/contract>
> > -#include <iostream>
> > +#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE
> > +# include <iostream>
> > +#endif
> >
> > __attribute__ ((weak)) void
> > handle_contract_violation (const std::experimental::contract_violation &violation)
> > {
> > - std::cerr << "default std::handle_contract_violation called: \n"
> > - << " " << violation.file_name()
> > - << " " << violation.line_number()
> > - << " " << violation.function_name()
> > - << " " << violation.comment()
> > - << " " << violation.assertion_level()
> > - << " " << violation.assertion_role()
> > - << " " << (int)violation.continuation_mode()
> > - << std::endl;
> > +#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE
> > + bool level_default_p = violation.assertion_level() == "default";
> > + bool role_default_p = violation.assertion_role() == "default";
> > + bool cont_mode_default_p = violation.continuation_mode()
> > + == std::experimental::contract_violation_continuation_mode::never_continue;
> > +
> > + const char* modes[]{ "off", "on" }; // Must match enumerators in header.
> > + std::cerr << "contract violation in function " << violation.function_name()
> > + << " at " << violation.file_name() << ':' << violation.line_number()
> > + << ": " << violation.comment();
> > +
> > + const char* delimiter = "\n[";
> > +
> > + if (!level_default_p)
> > + {
> > + std::cerr << delimiter << "level:" << violation.assertion_level();
> > + delimiter = ", ";
> > + }
> > + if (!role_default_p)
> > + {
> > + std::cerr << delimiter << "role:" << violation.assertion_role();
> > + delimiter = ", ";
> > + }
> > + if (!cont_mode_default_p)
> > + {
> > + std::cerr << delimiter << "continue:"
> > + << modes[(int)violation.continuation_mode() & 1];
> > + delimiter = ", ";
> > + }
> > +
> > + if (delimiter[0] == ',')
> > + std::cerr << ']';
> > +
> > + std::cerr << std::endl;
> > +#endif
> > }
> > -
>
next prev parent reply other threads:[~2022-12-22 22:02 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-10 9:42 [PATCH 0/4] c++: Small tweaks to contracts Arsen Arsenović
2022-12-10 9:43 ` [PATCH 1/4] contracts: Lowercase {MAYBE,NEVER}_CONTINUE Arsen Arsenović
2022-12-10 11:15 ` Jonathan Wakely
2022-12-15 16:25 ` Jason Merrill
2022-12-15 17:39 ` Arsen Arsenović
2022-12-20 17:16 ` Jason Merrill
2022-12-10 9:43 ` [PATCH 2/4] libstdc++: Improve output of default contract violation handler [PR107792] Arsen Arsenović
2022-12-15 16:28 ` Jason Merrill
2022-12-15 17:43 ` Arsen Arsenović
2022-12-20 10:49 ` [PATCH 1/3] " Arsen Arsenović
2022-12-20 10:49 ` [PATCH 2/3] contracts: Update testsuite against new default viol. handler format Arsen Arsenović
2022-12-20 10:49 ` [PATCH 3/3] contrib: Add dg-out-generator.pl Arsen Arsenović
2022-12-20 15:57 ` Jonathan Wakely
2022-12-20 17:23 ` [PATCH 1/3] libstdc++: Improve output of default contract violation handler [PR107792] Jason Merrill
2022-12-22 11:03 ` Arsen Arsenović
2022-12-22 21:40 ` Jason Merrill
2022-12-22 22:02 ` Jonathan Wakely [this message]
2022-12-22 11:03 ` [PATCH 2/3] contracts: Update testsuite against new default viol. handler format Arsen Arsenović
2022-12-22 11:03 ` [PATCH 3/3] contrib: Add dg-out-generator.pl Arsen Arsenović
2022-12-22 21:43 ` Jason Merrill
2022-12-22 21:56 ` Arsen Arsenović
2022-12-22 22:21 ` Jason Merrill
2022-12-22 22:56 ` Arsen Arsenović
2022-12-10 9:43 ` [PATCH 3/4] contracts: Update testsuite against new default viol. handler format Arsen Arsenović
2022-12-10 9:43 ` [PATCH 4/4] contrib: Add dg-out-generator.pl Arsen Arsenović
2022-12-15 16:30 ` Jason Merrill
2022-12-15 17:30 ` Arsen Arsenović
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=CAH6eHdSCnJc-X7x5CESv7ZtwM1nRgzxivDaup3fy1R9K9YeArw@mail.gmail.com \
--to=jwakely.gcc@gmail.com \
--cc=arsen@aarsen.me \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=jwakely@redhat.com \
--cc=libstdc++@gcc.gnu.org \
/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).