From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 1C9553858C2A for ; Thu, 16 Nov 2023 17:20:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C9553858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1C9553858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700155228; cv=none; b=Z/Or6h/+VbHoBo2oUlwxFp7TdwPDgOMaYoKld1mtNPl7x9LLUZzf5e2JsiGUh0OdsoDPcGzeqFObucWXGe/dh7/I8toS6YMOwXJdLyAJ7uIQEKOt7lWz53TFPK8yDsnf3hSwnl7EnVaZ7dh/kKihkd/9V6yTnDqcp1A8bg6PfFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700155228; c=relaxed/simple; bh=0mkBAdFtdYk9ZllquR1WaW6MbiyPeWksfnsmtLuNJ48=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qCQ9JbkicKBZOTMtu7If3mPRoPYE8DYUoIxVx71k1HCYSUi8jRkDXcA9/Gjui8WbISBmoAFpjMbmk1BFhRzmh1sxhOqW1bjv0G0d3OwjCAZfuLKzPutEOV1TCl1MppxxZsZzVBQ31IdML/l2R7PaXAAlY7Ufsq/nGTA3a7Lqnwc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700155225; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Te3khevT/1tzwewaCrOnoILbUgFPsEdZR6Fh8BmrTls=; b=Nx8nGpLagY3WjwOOWk/jNpk3frVqiZ64GQg4vgOifEdDtXkxKJMhNGq+y+noj4TfETVfC5 00n1Zcb+hhS/N1BdF/qbK4mOk3pKJKtbtAAQwyFBSHBQq8Xe1MGqxhVHyNRfM9KbOt6voR itab8i/OCnnEXc1Cbr3xSj61tSzXnD8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-410-yCFJYDklOpWH1YdDWF7vCQ-1; Thu, 16 Nov 2023 12:20:22 -0500 X-MC-Unique: yCFJYDklOpWH1YdDWF7vCQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9F3F685A58A; Thu, 16 Nov 2023 17:20:22 +0000 (UTC) Received: from localhost (unknown [10.42.28.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DB912166B27; Thu, 16 Nov 2023 17:20:22 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix aligned formatting of stacktrace_entry and thread::id [PR112564] Date: Thu, 16 Nov 2023 17:20:09 +0000 Message-ID: <20231116172021.1344351-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT 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: Tested x86_64-linux. Pushed to trunk. -- >8 -- The formatter for std::thread::id should default to right-align, and the formatter for std::stacktrace_entry should not just ignore the fill-and-align and width from the format-spec! libstdc++-v3/ChangeLog: PR libstdc++/112564 * include/std/stacktrace (formatter::format): Format according to format-spec. * include/std/thread (formatter::format): Use _Align_right as default. * testsuite/19_diagnostics/stacktrace/output.cc: Check fill-and-align handling. Change compile test to run. * testsuite/30_threads/thread/id/output.cc: Check fill-and-align handling. --- libstdc++-v3/include/std/stacktrace | 4 +++- libstdc++-v3/include/std/thread | 3 ++- .../19_diagnostics/stacktrace/output.cc | 18 +++++++++++++++--- .../testsuite/30_threads/thread/id/output.cc | 14 ++++++++++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index 9d5f6396aed..f570745fe51 100644 --- a/libstdc++-v3/include/std/stacktrace +++ b/libstdc++-v3/include/std/stacktrace @@ -740,7 +740,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { std::ostringstream __os; __os << __x; - return __format::__write(__fc.out(), __os.view()); + auto __str = __os.view(); + return __format::__write_padded_as_spec(__str, __str.size(), + __fc, _M_spec); } private: diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread index 39042d7cdf5..ee3b8b1fcb0 100644 --- a/libstdc++-v3/include/std/thread +++ b/libstdc++-v3/include/std/thread @@ -335,7 +335,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __os << __id; auto __str = __os.view(); return __format::__write_padded_as_spec(__str, __str.size(), - __fc, _M_spec); + __fc, _M_spec, + __format::_Align_right); } private: diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc index 4960ccb85b8..67f1e0cebaf 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc @@ -1,4 +1,5 @@ -// { dg-do compile { target c++23 } } +// { dg-options "-lstdc++exp" } +// { dg-do run { target c++23 } } // { dg-require-effective-target stacktrace } // { dg-add-options no_pch } @@ -17,7 +18,8 @@ test_to_string() { auto trace = std::stacktrace::current(); std::string s1 = std::to_string(trace.at(0)); - VERIFY( s1.contains("test_to_string():15") ); + VERIFY( s1.contains("test_to_string()") ); + VERIFY( s1.contains("output.cc:19") ); std::string s2 = std::to_string(trace); VERIFY( s2.contains(s1) ); } @@ -47,7 +49,17 @@ test_format() std::stacktrace_entry entry = trace.at(0); std::string str = std::to_string(entry); VERIFY( std::format("{}", entry) == str ); - VERIFY( std::format("{0:!<{1}}", entry, str.size() + 3) == (str + "!!!") ); + auto len = str.size(); + // with width + VERIFY( std::format("{0:{1}}", entry, len + 1) == (str + " ") ); + // with align + width + VERIFY( std::format("{0:<{1}}", entry, len + 2) == (str + " ") ); + VERIFY( std::format("{0:^{1}}", entry, len + 3) == (" " + str + " ") ); + VERIFY( std::format("{0:>{1}}", entry, len + 4) == (" " + str) ); + // with fill-and-align + width + VERIFY( std::format("{0:!<{1}}", entry, len + 2) == (str + "!!") ); + VERIFY( std::format("{0:!^{1}}", entry, len + 3) == ("!" + str + "!!") ); + VERIFY( std::format("{0:!>{1}}", entry, len + 4) == ("!!!!" + str) ); } int main() diff --git a/libstdc++-v3/testsuite/30_threads/thread/id/output.cc b/libstdc++-v3/testsuite/30_threads/thread/id/output.cc index 08d8c899fda..3c167202b02 100644 --- a/libstdc++-v3/testsuite/30_threads/thread/id/output.cc +++ b/libstdc++-v3/testsuite/30_threads/thread/id/output.cc @@ -80,8 +80,18 @@ test02() auto len = s1.size(); out.str(""); - auto s2 = std::format("{0:x^{1}}", j, len + 4); - VERIFY( s2 == ("xx" + s1 + "xx") ); + std::string s2; + // with width + s2 = std::format("{0:{1}}", j, len + 2); + VERIFY( s2 == (" " + s1) ); + // with align + width + s2 = std::format("{0:>{1}}", j, len + 2); + VERIFY( s2 == (" " + s1) ); + s2 = std::format("{0:<{1}}", j, len + 2); + VERIFY( s2 == (s1 + " ") ); + // with fill-and-align + width + s2 = std::format("{0:x^{1}}", j, len + 5); + VERIFY( s2 == ("xx" + s1 + "xxx") ); #ifdef _GLIBCXX_USE_WCHAR_T static_assert( std::is_default_constructible_v> ); -- 2.41.0