From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by sourceware.org (Postfix) with ESMTPS id 2886138432CB; Sat, 10 Dec 2022 09:49:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2886138432CB Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4NTjlR5dBFz9sTL; Sat, 10 Dec 2022 10:49:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1670665747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kH/0kGDWDARbemI52/Nka2SVky9xvP6k0BzXmOkpgFo=; b=RfNa2S0FykkmtdROX84tg8rdvDIk6DwolRq1fARXChBxNSmvnER3I6BDwhwgGR3yrgI+iQ awP7elo80lAsfFD4KFVu5IealY88xro4RQBZkQimevlRzrIFVrsTuKRlvDeiFYab59xn1e iKyLK88ljiHbfEHO4elPhO1zaTO7uAAw2z3KoWbnv7nXbBx12mNi5EMfjsxHNdtsr2PXlX SmxK5Jz4ZzpT8PcZhWKndbXF4CTMu4u6nkJN+sCwtFuQaMao1/iQVGIXJywW9RpUZtBBQO S3MLetupr6Piz6zti/Ka23XMVpwj0nUU4Bs2DmNph6fvK1pXkyWddIybh6Al3A== From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, jwakely@redhat.com, libstdc++@gcc.gnu.org Subject: [PATCH 2/4] libstdc++: Improve output of default contract violation handler [PR107792] Date: Sat, 10 Dec 2022 10:43:01 +0100 Message-Id: <20221210094303.2180127-3-arsen@aarsen.me> In-Reply-To: <20221210094303.2180127-1-arsen@aarsen.me> References: <20221210094303.2180127-1-arsen@aarsen.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_INFOUSMEBIZ,KAM_SHORT,RCVD_IN_DNSWL_LOW,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: From: Jonathan Wakely Make the output more readable. Don't output anything unless verbose termination is enabled at configure-time. libstdc++-v3/ChangeLog: PR libstdc++/107792 PR libstdc++/107778 * src/experimental/contract.cc (handle_contract_violation): Make output more readable. --- libstdc++-v3/src/experimental/contract.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/src/experimental/contract.cc b/libstdc++-v3/src/experimental/contract.cc index c8d2697eddc..6a7f064d35e 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,21 @@ // . #include -#include +#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE +# include +#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() +#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE + const char* modes[]{ "never", "maybe" }; // Must match enumerators in header. + std::cerr << "contract violation in function " << violation.function_name() + << " at " << violation.file_name() << ':' << violation.line_number() + << ": " << violation.comment() + << "\n[level:" << violation.assertion_level() + << ", role:" << violation.assertion_role() << ", continuation mode:" + << modes[(int)violation.continuation_mode()] << ']' << std::endl; +#endif } - -- 2.38.1