From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id C789B3857C7C for ; Mon, 24 Aug 2020 15:17:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C789B3857C7C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-63-1DGwzp4GOjGFom3IbE3Utw-1; Mon, 24 Aug 2020 11:16:59 -0400 X-MC-Unique: 1DGwzp4GOjGFom3IbE3Utw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0DA8681F022; Mon, 24 Aug 2020 15:16:58 +0000 (UTC) Received: from localhost (unknown [10.33.36.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABC235C1DA; Mon, 24 Aug 2020 15:16:57 +0000 (UTC) Date: Mon, 24 Aug 2020 16:16:56 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Make variant_npos conversions explicit [PR 96766] Message-ID: <20200824151656.GA648587@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="ReaqsoxgOBHFXBhH" Content-Disposition: inline X-Spam-Status: No, score=-14.4 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, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Mon, 24 Aug 2020 15:17:04 -0000 --ReaqsoxgOBHFXBhH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline libstdc++-v3/ChangeLog: PR libstdc++/96766 * include/std/variant (_Variant_storage): Replace implicit conversions from size_t to __index_type with explicit casts. This fixes a silly Clang UBsan warning from its silly unsigned-integer-overflow sanitizer which complains about perfectly valid code doing exactly what it's intended to. How silly. Tested powerpc64le-linux, and with Clang. Committed to trunk. I'll backport this to the branches, because people use clang's silly sanitizer with the branches too. --ReaqsoxgOBHFXBhH Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 074436cf8cdd2a9ce75cadd36deb8301f00e55b9 Author: Jonathan Wakely Date: Mon Aug 24 16:10:07 2020 libstdc++: Make variant_npos conversions explicit [PR 96766] libstdc++-v3/ChangeLog: PR libstdc++/96766 * include/std/variant (_Variant_storage): Replace implicit conversions from size_t to __index_type with explicit casts. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index eb3d6779205..dd8847cf829 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -385,12 +385,16 @@ namespace __variant template struct _Variant_storage { - constexpr _Variant_storage() : _M_index(variant_npos) { } + constexpr + _Variant_storage() + : _M_index(static_cast<__index_type>(variant_npos)) + { } template - constexpr _Variant_storage(in_place_index_t<_Np>, _Args&&... __args) + constexpr + _Variant_storage(in_place_index_t<_Np>, _Args&&... __args) : _M_u(in_place_index<_Np>, std::forward<_Args>(__args)...), - _M_index(_Np) + _M_index{_Np} { } void _M_reset() @@ -403,7 +407,7 @@ namespace __variant std::_Destroy(std::__addressof(__this_mem)); }, __variant_cast<_Types...>(*this)); - _M_index = variant_npos; + _M_index = static_cast<__index_type>(variant_npos); } ~_Variant_storage() @@ -432,16 +436,20 @@ namespace __variant template struct _Variant_storage { - constexpr _Variant_storage() : _M_index(variant_npos) { } + constexpr + _Variant_storage() + : _M_index(static_cast<__index_type>(variant_npos)) + { } template - constexpr _Variant_storage(in_place_index_t<_Np>, _Args&&... __args) + constexpr + _Variant_storage(in_place_index_t<_Np>, _Args&&... __args) : _M_u(in_place_index<_Np>, std::forward<_Args>(__args)...), - _M_index(_Np) + _M_index{_Np} { } void _M_reset() noexcept - { _M_index = variant_npos; } + { _M_index = static_cast<__index_type>(variant_npos); } void* _M_storage() const noexcept @@ -455,7 +463,7 @@ namespace __variant { if constexpr (__variant::__never_valueless<_Types...>()) return true; - return this->_M_index != __index_type(variant_npos); + return this->_M_index != static_cast<__index_type>(variant_npos); } _Variadic_union<_Types...> _M_u; --ReaqsoxgOBHFXBhH--