From patchwork Tue Mar 26 14:11:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 1065620 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-498451-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="B+V18K1G"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="h27qmgJE"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44TCkS0K78z9sSk for ; Wed, 27 Mar 2019 01:12:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=JNzcIr92WtVFMbfFkrB6iixht7e6uECu29gL/UIAmj0v2y 2/6fHtuVD49bLnvCJiuQvtIPLG89JjWW02KrglA8BlP13nB/Wb1jrmmZZF3rG4Gi hbuHnh1mVvil1tXc5Yf7XJekSwq+HMcK4D/NbdMM1QsReQBhXtU/2Oua34mfY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=ujVH9qJPw+f3iCyyfIfy8sQclBo=; b=B+V18K1GQYHo3rRm5kry agInVuErlOMr1FEA7ZLfQXsQsgxAMizWgiT66+k8a0isnhU52bj8nnDN2ASQ/LSL W9xVNeMSkaYK444VcL+ei/7T3o4HsDdOVf2ijrELbwepTpUv5btR0ZJhjjLDdkxk VOVcZU2XroCxr2zbR0wzFQI= Received: (qmail 22538 invoked by alias); 26 Mar 2019 14:12:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 22227 invoked by uid 89); 26 Mar 2019 14:12:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-ot1-f50.google.com Received: from mail-ot1-f50.google.com (HELO mail-ot1-f50.google.com) (209.85.210.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Mar 2019 14:12:01 +0000 Received: by mail-ot1-f50.google.com with SMTP id k21so10193638otf.1; Tue, 26 Mar 2019 07:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Rzs/mmoFSFCJ6DsCDEKDXb+/aUDsjXtvQp0B8jdUv6E=; b=h27qmgJEuV15TQ2aybPIdrKtf167L/sxAYnjLhuZD/D7owDcZRAOcuJnlW7Hbm50iO Tdv90L6Vjsk1xvJilGyvbawdYJ3SPGYM5brDx2gXHRlv3ivhOACSvj0UEDBoV61vgQJy 7zmFCzPT6FR88h080tVqBTtnMnbYbF9gnylluuTkyP5XTZMMJqm9ez7LhHJwWGFe2ptr Dd6ij37H9q9VaZIMFAhpzsmrfk1ysUzAeXJ3BLz+ZuiTgvJdneXfvnxrLl77t7kDhkTH t0WuqNIynzj8TvtViwEOZcF8fYbj0Kw8Mtgt7TfW6kWmWmrmXwAQh+NpK6Ec4uMKNvAO uRBw== MIME-Version: 1.0 From: Ville Voutilainen Date: Tue, 26 Mar 2019 16:11:47 +0200 Message-ID: Subject: [v3 PATCH] PR libstdc++/89825 To: "libstdc++" , gcc-patches List 2019-03-26 Ville Voutilainen PR libstdc++/89825 Fix based on a suggestion by Antony Polukhin. * include/std/variant (_Extra_visit_slot_needed): New. (_Multi_array): Use it. (_S_apply_all_alts): Likewise. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 3631463..27ea516 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -747,6 +747,20 @@ namespace __variant void* __get_storage(_Variant&& __v) { return __v._M_storage(); } + template + struct _Extra_visit_slot_needed + { + template struct _Variant_never_valueless; + + template + struct _Variant_never_valueless> + : bool_constant<(is_trivially_copyable_v<_Types>&&...)> {}; + + static constexpr bool value = + is_same_v<_Maybe_variant_cookie, __variant_cookie> + && !_Variant_never_valueless<__remove_cvref_t<_Variant>>::value; + }; + // Used for storing multi-dimensional vtable. template struct _Multi_array @@ -764,8 +778,11 @@ namespace __variant size_t __first, size_t... __rest> struct _Multi_array<_Ret(*)(_Visitor, _Variants...), __first, __rest...> { + static constexpr size_t __index = + sizeof...(_Variants) - sizeof...(__rest) - 1; + using _Variant = typename _Nth_type<__index, _Variants...>::type; static constexpr int __do_cookie = - is_same_v<_Ret, __variant_cookie> ? 1 : 0; + _Extra_visit_slot_needed<_Ret, _Variant>::value ? 1 : 0; using _Tp = _Ret(*)(_Visitor, _Variants...); template constexpr const _Tp& @@ -832,7 +849,7 @@ namespace __variant _S_apply_all_alts(_Array_type& __vtable, std::index_sequence<__var_indices...>) { - if constexpr (is_same_v<_Result_type, __variant_cookie>) + if constexpr (_Extra_visit_slot_needed<_Result_type, _Next>::value) (_S_apply_single_alt( __vtable._M_arr[__var_indices + 1], &(__vtable._M_arr[0])), ...);