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.129.124]) by sourceware.org (Postfix) with ESMTPS id 8E4353858D20 for ; Fri, 14 Apr 2023 11:00:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E4353858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681470025; 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=/CmeUUmjLEfNsqnn+1INEcRl9zc2grHcwsQYvUgZvvI=; b=CKlWaEDUFeUOvW/2j1b3jBKFNwMwbJLMKoWSdpgmHlp+beB5UL5gyM+WA9HCe1XAiIa1bh mqa0wmZbder0BHojxD1RnoeS+RLVv927S3LhRFbhYH6UjrDQACpscZDJUsNMUSQE+vSVLY TnM4GKV4gfXHX760EhMNouE56LXGKIM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-463-pKc7Jp8INXqgHy8zJdBDSg-1; Fri, 14 Apr 2023 07:00:23 -0400 X-MC-Unique: pKc7Jp8INXqgHy8zJdBDSg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 95A042802E21; Fri, 14 Apr 2023 11:00:23 +0000 (UTC) Received: from localhost (unknown [10.33.36.209]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F99C2166B26; Fri, 14 Apr 2023 11:00:23 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Improve diagnostics for invalid std::format calls Date: Fri, 14 Apr 2023 12:00:22 +0100 Message-Id: <20230414110022.359953-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.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=-12.1 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_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 powerpc64le-linux. Pushed to trunk. -- >8 -- Add a static_assert and a comment so that calling std::format for unformattable argument types will now show: /home/jwakely/gcc/13/include/c++/13.0.1/format:3563:22: error: static assertion failed: std::formatter must be specialized for each format arg 3563 | static_assert((is_default_constructible_v> && ...), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ and: 140 | formatter() = delete; // No std::formatter specialization for this type. libstdc++-v3/ChangeLog: * include/std/format (formatter): Add comment to deleted default constructor of primary template. (_Checking_scanner): Add static_assert. --- libstdc++-v3/include/std/format | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 72b6b450ad1..e4ef4f9b6d9 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -137,7 +137,7 @@ namespace __format template struct formatter { - formatter() = delete; + formatter() = delete; // No std::formatter specialization for this type. formatter(const formatter&) = delete; formatter& operator=(const formatter&) = delete; }; @@ -3560,6 +3560,10 @@ namespace __format template class _Checking_scanner : public _Scanner<_CharT> { + static_assert( + (is_default_constructible_v> && ...), + "std::formatter must be specialized for each type being formatted"); + public: constexpr _Checking_scanner(basic_string_view<_CharT> __str) @@ -3581,17 +3585,17 @@ namespace __format __builtin_unreachable(); } - template + template constexpr void _M_parse_format_spec(size_t __id) { if (__id == 0) { - formatter<_Head, _CharT> __f; + formatter<_Tp, _CharT> __f; this->_M_pc.advance_to(__f.parse(this->_M_pc)); } - else if constexpr (sizeof...(_Tail) != 0) - _M_parse_format_spec<_Tail...>(__id - 1); + else if constexpr (sizeof...(_OtherArgs) != 0) + _M_parse_format_spec<_OtherArgs...>(__id - 1); else __builtin_unreachable(); } -- 2.39.2