From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 45E30385800F for ; Mon, 28 Dec 2020 20:47:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 45E30385800F Received: by mail-wr1-x433.google.com with SMTP id q18so12522918wrn.1 for ; Mon, 28 Dec 2020 12:47:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Vl2wwaMkqKJLclvEbSfn+JuXIi/qmqFvYEc0enadQ6Q=; b=ZlKF0KvWum4nXjoQ/xh6DoZVWOsWrFTHDwNq7MTkkMg+ajdeq5bsfa2uhcSr5uN/XH PADaP7jkIDAmXJ9Oell+rVBpmNQs/kmsL3gQVUwEF3fZvkup79PC+Ui+9ri/HLVleGbc D9h1RXhASygkCoKHfFoyCNrARjjWVPaHR49DGNNwk1TroB2gO/ybfm/bycG9FOyFf3cP t9Hbi/UxyPjWpMZ7Amo2WVzSN5ybBzemj9XZQgKgwtI6qt7VyRbihgIWIvh1XsDszLzy pUZFEb08oYdFD+wXoviL7z72I7HmurlDt0hOX3IGG+Ye2vAm0Kobh9bpoFLTy5xf6nPE O3Gw== X-Gm-Message-State: AOAM531bd3HheFATe/CdzuoBrRq6jqTpkIRfVjcEue6l4synJ6dbuN14 ienYJSmSVMNTiAaB/Ukv5DD6HVfsGccwDmCYpu0= X-Google-Smtp-Source: ABdhPJxfiPrEFnwdp5ybC9ASK1gNhYUZJ8ECf+xdD+rv+grXO6EnSDlyrnynoONmFQxHTGQKmn96Vs2Gp4Kbob/Wo3U= X-Received: by 2002:a5d:4e8c:: with SMTP id e12mr51207187wru.321.1609188433332; Mon, 28 Dec 2020 12:47:13 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Mon, 28 Dec 2020 20:47:02 +0000 Message-ID: Subject: Re: Should reinterpret_cast be constexpr? To: Josh Marshall Cc: "libstdc++" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Dec 2020 20:47:15 -0000 On Mon, 28 Dec 2020 at 20:33, Jonathan Wakely wrote: > > On Mon, 28 Dec 2020 at 19:51, Josh Marshall via Libstdc++ > wrote: > > > > Hello all, > > > > From the test error `libstdc++-v3/include/bits/stl_vector.h:1837: error: > > 'reinterpret_cast' is not a constant expression` and the documentation at > > https://en.cppreference.com/w/cpp/language/reinterpret_cast , is > > `reinterpret_cast()` not constexpr in error? > > No, it's not an error. reinterpret_cast is not allowed in constant expressions. This patch replaces the use of reinterpret_cast with an alternative using C++20 features: diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index 27e63388feb..93b2ccc02e3 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -516,9 +516,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { #if __cplusplus < 201103L value_type __x_copy = __x; -#else +#elif ! __cpp_lib_make_obj_using_allocator _Temporary_value __tmp(this, __x); value_type& __x_copy = __tmp._M_val(); +#else + value_type __x_copy = std::make_from_tuple( + std::uses_allocator_construction_args( + _M_get_Tp_allocator(), __x)); #endif const size_type __elems_after = end() - __position; pointer __old_finish(this->_M_impl._M_finish);