From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 3C3CE3858D1E; Thu, 22 Dec 2022 22:02:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3C3CE3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x536.google.com with SMTP id a1so4778361edf.5; Thu, 22 Dec 2022 14:02:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YsLjUtqjvHxzkEHKtdTD3wz/fURX1ruKrVVrW1mv7TM=; b=BlsW7Behb8409eiqCN54WF2Boa4+vShgQkTiKO1N9Q3ndAFYzAMBcCKBbeRDjxDez4 uqu+qBAqll0Oex2Y7w7bvM13/DElZI000UGSWlC8P34qIQ1yV6C/I9qPoaBYasTmuGFR VpUV2snjyNDzvbq7mllGz90WeEcNY4WLu2HMA/NeyTqDHiq8OcacNiTnQGFLMQ6tDHG4 A+oh4/hIXDZUvOrFKv9qr2TANKqstxgcyrcCV0MoAVlsNSk+dqO3hNnbBwBHgiKmlTMz Mmjp4G/Lmh4D0LWrTyP2w0LpqyR++pzvndq7DFx0zuE0bzUkFtCihDtaylZj1bBUL8HI 3olQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YsLjUtqjvHxzkEHKtdTD3wz/fURX1ruKrVVrW1mv7TM=; b=CThEgMAvtTbn6OUTOJDX52XN5PXhbDMqdFUVsj9Jnu3Jpe8uWaEypnoCqb7F82LRYC ZC7IERSe7+WnJg6rlBH9avOl5prYVWgQHmuONcPXcYThU4yncVacSo/lztPfToDWZDuh RT8jLN8YHsWExTSnQVsvBnObnvDbVgDVN7ASRWlF3JrucRnzevBeo1mJKI4hv+htSxqm sebMNy4a9XOqfy2GyaM2RtMnSkTrqZpbMgdbLq/HjyMAjnttzIRxRAXXrYfdnhBPWZOw S4droCvfwwSrWjs9zfRqfq+7VKc3AvodXnLOT3H2w88aqxoofaA1S4MK+QCWAa5+DCzW w/OA== X-Gm-Message-State: AFqh2kolnBElFOCnj6dUHqDKlCw0F3eq/ZHwO8rmows5nodYXc5fkDFZ WbTiIhUs64oIk0Yf/HS/0Oiy31JY1pMj8gKfddc= X-Google-Smtp-Source: AMrXdXuu+opKp0WY9KAoI0ke+UJq90tax7HJ2GrdyWRGfTYYj43iqWgw6vprwq9Tgs7ZY3tw4zEjgT0BUSXokRHwZqU= X-Received: by 2002:aa7:c6c2:0:b0:47b:a8d:9a16 with SMTP id b2-20020aa7c6c2000000b0047b0a8d9a16mr791458eds.33.1671746538874; Thu, 22 Dec 2022 14:02:18 -0800 (PST) MIME-Version: 1.0 References: <20221222110306.3869396-1-arsen@aarsen.me> <3ebc61d5-f662-7064-8b03-d7689cd1bb4a@redhat.com> In-Reply-To: <3ebc61d5-f662-7064-8b03-d7689cd1bb4a@redhat.com> From: Jonathan Wakely Date: Thu, 22 Dec 2022 22:02:07 +0000 Message-ID: Subject: Re: [PATCH 1/3] libstdc++: Improve output of default contract violation handler [PR107792] To: Jason Merrill Cc: =?UTF-8?Q?Arsen_Arsenovi=C4=87?= , gcc-patches@gcc.gnu.org, jwakely@redhat.com, libstdc++@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 22 Dec 2022 at 21:41, Jason Merrill via Libstdc++ wrote: > > On 12/22/22 06:03, Arsen Arsenovi=C4=87 wrote: > > From: Jonathan Wakely > > > > 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 i= t. > > > 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/s= rc/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 @@ > > // . > > > > #include > > -#include > > +#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE > > +# include > > +#endif > > > > __attribute__ ((weak)) void > > handle_contract_violation (const std::experimental::contract_violatio= n &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 =3D violation.assertion_level() =3D=3D "default= "; > > + bool role_default_p =3D violation.assertion_role() =3D=3D "default"; > > + bool cont_mode_default_p =3D violation.continuation_mode() > > + =3D=3D std::experimental::contract_violation_continuation_mode::ne= ver_continue; > > + > > + const char* modes[]{ "off", "on" }; // Must match enumerators in hea= der. > > + std::cerr << "contract violation in function " << violation.function= _name() > > + << " at " << violation.file_name() << ':' << violation.line_number= () > > + << ": " << violation.comment(); > > + > > + const char* delimiter =3D "\n["; > > + > > + if (!level_default_p) > > + { > > + std::cerr << delimiter << "level:" << violation.assertion_level(= ); > > + delimiter =3D ", "; > > + } > > + if (!role_default_p) > > + { > > + std::cerr << delimiter << "role:" << violation.assertion_role(); > > + delimiter =3D ", "; > > + } > > + if (!cont_mode_default_p) > > + { > > + std::cerr << delimiter << "continue:" > > + << modes[(int)violation.continuation_mode() & 1]; > > + delimiter =3D ", "; > > + } > > + > > + if (delimiter[0] =3D=3D ',') > > + std::cerr << ']'; > > + > > + std::cerr << std::endl; > > +#endif > > } > > - >