From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by sourceware.org (Postfix) with ESMTPS id B30AE3858D1E; Thu, 22 Dec 2022 11:03:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B30AE3858D1E 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 smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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-102.mailbox.org (Postfix) with ESMTPS id 4Nd6r4461Tz9sTG; Thu, 22 Dec 2022 12:03:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1671707028; 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=NX2fBlCQNrqoF3T5hf7SVMX7kv8jJAIodXSS6ZsIPqQ=; b=piNoNqy8qe0jUsmY2wC3vwAT6k1UNwtDcCyp4FvG64kvOTqgp2ucmLzSWxqTukZd/ya+Y2 Brq2TOHcGuIPENyX5833pKOhR42i1Q70tnQYquzNJPkfK5DJRJOTY35GHRJckOEJK01BpQ HS/nx/aBxXx9y1uqnDnGbzajvl0noP8x8kOQVMBf4mfsljdxXD7EDs9cfvCTwsHlG6DAH7 o//ZlnxA0u90beI6ov7A7T8h8CTZwoQbkRzWd6TlTjhOeYRDRn3QJ8+rgzhV0hVpjWBFD5 /8emgiklynloDuRsbtTfeaKmrWP89sS0dMP+y6djc0b+Oz4ngxUmH8I6v1l/Fg== From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, jwakely@redhat.com, libstdc++@gcc.gnu.org, arsen@aarsen.me Subject: [PATCH 1/3] libstdc++: Improve output of default contract violation handler [PR107792] Date: Thu, 22 Dec 2022 12:03:06 +0100 Message-Id: <20221222110306.3869396-1-arsen@aarsen.me> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4Nd6r4461Tz9sTG X-Spam-Status: No, score=-11.1 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. --- 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 @@ // . #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() - << 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 } - -- 2.39.0