From patchwork Fri Apr 14 11:00:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 83349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp289088vqo; Fri, 14 Apr 2023 04:01:11 -0700 (PDT) X-Google-Smtp-Source: AKy350YnSVh1Yqsas1qzOsNWx1uiPrKwZ1H9oJdAT+vYog5oQPkOA8yvqIpMbkzY+dwaYyPS/YNY X-Received: by 2002:a17:906:f8f:b0:889:5686:486a with SMTP id q15-20020a1709060f8f00b008895686486amr6223129ejj.30.1681470071207; Fri, 14 Apr 2023 04:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681470071; cv=none; d=google.com; s=arc-20160816; b=GEXGGvEKL8+dJUjP8B3+Dbrd0kbUgHLPmeulgZ5gHsURwzMSskyJql3wHLEKgL6ILz GpMmFhEZoSImCGKTlwDkjz+C67VXTg33vjAyo2db282xeLEqOwiAy3QTw49jMKG71923 tw6YUOShmozDcyPw0SVIMBUgHjeVoqEq5NXJD0HPma+guJGp7aqsTx3b0O8i7rjvj+6X LytSSP8Mo5cuzz9tuiqqKt2CovgOr1cejR7TQXE+sDWxI/5rS5v5I+3/sry8NpGAa/xQ j14lAjqNU/6gBm73PKj5biBLdN4uIrOWOdImyx/+hklxPT2vcPhR5V26UgfYkCvpU9vz 3QuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=/CmeUUmjLEfNsqnn+1INEcRl9zc2grHcwsQYvUgZvvI=; b=acUKIQ6gfmu14wwvekw6Zb3/3XIsMnV+yGhv0hShYt3/kGgkVRUzIZOx5kuSQl22/u ccl9/fMY91XzZrw9tw7EgCxZMkwKG18q1mga+6rMUJPaS188Qz8kX7eu/zU+TuMcbg+b BauprCyBdkgyDKND1/KuBgu7SiJZf55mQmKzzsZB68q3cV7PmQnuNCEmoan+s+SiKZWY y40qyMZV+9wb5lkjVg2IdGexdd6jxJSxk5IDLr6MC5hlcKbjYCAoIgoxvURGz257UcdT Hbs7q+y3xrwpW+kM17XIKqwDQ2L2o4BUUAVHujiDyc0uJ1Cq8IOQY1HG6HZLeZdFzKK7 eg0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="HPl6V+9/"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id we7-20020a170907234700b0094af9b72966si4238887ejb.1050.2023.04.14.04.01.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 04:01:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="HPl6V+9/"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF6D63857700 for ; Fri, 14 Apr 2023 11:01:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF6D63857700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681470069; bh=/CmeUUmjLEfNsqnn+1INEcRl9zc2grHcwsQYvUgZvvI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=HPl6V+9/pAamfgJxOiaofFj4TOzfzKBzk5OSEn49s/+NBja7IF3+WAqGecrT2zC0y HEfffoAI9W8dt/STo+yEGuZJQco0+xuV1iesVOZY5VtZbq6flc0n3Iv54mrmkUU/l2 LYPT3S26USHXg7Ihn1+/F6qbAF6E33uHiVJwLEj4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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) 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763149161213096633?= X-GMAIL-MSGID: =?utf-8?q?1763149161213096633?= 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(); }