From patchwork Sun Sep 15 15:18:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1985876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GVQm6wcS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X6BXw4QVZz1y1T for ; Mon, 16 Sep 2024 01:19:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F0CF385841C for ; Sun, 15 Sep 2024 15:19:26 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTP id E79CB385C6C3 for ; Sun, 15 Sep 2024 15:18:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E79CB385C6C3 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 E79CB385C6C3 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=1726413533; cv=none; b=n2ol4XxJAEkiHjmj0t/HCE5BZcafl1zxqRavq4o0csgcbIoEJI/k1Q68JOtElpn0dspZQ2FgCz2X+ITCJGsTscb5bB2JjAUk8BeBe4fJvS7gH5D4cDP4NtywssYqdf6K10lERBzfyeDD+OjdcMhkHgKmd87WlQiAgFccX/ZM+8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726413533; c=relaxed/simple; bh=VL8Fyp/i4v6Fbr5GCv54NpUFKhE6FVnLzuvljGuQInM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VpaYEbv0d+MGhHzhJnXEYn8/XGHAo+DhiD3XHFHrxjszsRQ22j/WU6WFkpFKqDK0MwrB/AeAqLk0RAhscHxK53uQ1LPllLp8iJcMwHQIAaJXLeee7dU+sUgIJ5YCptQ5ZwFNLjzt2+1wYclSYUWxzr7Zi+7KCsdLQP04WO90MI8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726413531; 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=yOT782RlRyYjFTf6p+O8m/cGis8+O06NGLzQZA+zBTM=; b=GVQm6wcS8ghvSPVCuSMqoeaD2OaxqhbRzxY0DcWb3arYnJ649ZSryNbhdjCx4XQXoSVq63 wc0l9QxkhQ7Nki9xlsqctqE2KCPxdnFLMmmJ+EyBKSBehZ69wI0DlXyWJ6++HHg/OdZAHz IRxoMeFrBkITx7l5/0urxyAJMU3SSV8= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-360-8Tw8oREfOY6liOblTKp8Gw-1; Sun, 15 Sep 2024 11:18:50 -0400 X-MC-Unique: 8Tw8oREfOY6liOblTKp8Gw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 44E2419560A3; Sun, 15 Sep 2024 15:18:49 +0000 (UTC) Received: from localhost (unknown [10.45.224.43]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E9A61956054; Sun, 15 Sep 2024 15:18:48 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add assertion for valid facet type arguments Date: Sun, 15 Sep 2024 16:18:35 +0100 Message-ID: <20240915151846.26403-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 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 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- LWG 436 confirmed that const-qualified types are valid arguments for Facet template parameters, but volatile-qualified types are not. Add an assertion to locale::combine to check for valid types. libstdc++-v3/ChangeLog: * include/bits/locale_classes.h (__is_facet): New helper. * include/bits/locale_classes.tcc (locale::combine): Check that _Facet type is valid. --- libstdc++-v3/include/bits/locale_classes.h | 6 ++++++ libstdc++-v3/include/bits/locale_classes.tcc | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/libstdc++-v3/include/bits/locale_classes.h b/libstdc++-v3/include/bits/locale_classes.h index 50a748066f1..e168881b516 100644 --- a/libstdc++-v3/include/bits/locale_classes.h +++ b/libstdc++-v3/include/bits/locale_classes.h @@ -381,6 +381,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif }; +#if __cpp_lib_type_trait_variable_templates // C++ >= 17 + template + constexpr bool __is_facet = is_base_of_v; + template + constexpr bool __is_facet = false; +#endif // 22.1.1.1.2 Class locale::facet /** diff --git a/libstdc++-v3/include/bits/locale_classes.tcc b/libstdc++-v3/include/bits/locale_classes.tcc index d5ef1911057..1b5f5f2417c 100644 --- a/libstdc++-v3/include/bits/locale_classes.tcc +++ b/libstdc++-v3/include/bits/locale_classes.tcc @@ -71,6 +71,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION locale:: combine(const locale& __other) const { +#if __cpp_lib_type_trait_variable_templates // C++ >= 17 + static_assert(__is_facet<_Facet>, "Template argument must be a facet"); +#endif + _Impl* __tmp = new _Impl(*_M_impl, 1); __try {