From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Cc: Tim Shen <timshen@google.com>, Tim Song <t.canens.cpp@gmail.com>
Subject: [PATCH] PR libstdc++/80939 Remove unmeetable constexpr specifiers
Date: Fri, 02 Jun 2017 13:07:00 -0000 [thread overview]
Message-ID: <20170602130734.GA6233@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 854 bytes --]
As the PR points out, we aren't qualifying calls to __ref_cast, and
have 'constexpr' on function templates that can never be usable in
constant expressions.
This fixes it, and also simplifies __variant::__erased_dtor by using
std::_Destroy, although that requires including quite a lot more code,
for iterator_traits and allocator_traits. If that matters (probably
not) then <bits/stl_construct.h> could be split up to move _Construct
and _Destroy to a new <bits/stl_construct_base.h>. Or maybe I should
just leave __erased_dtor alone (apart from qualifying the __ref_cast
call).
Anybody feel strongly either way?
PR libstdc++/80939
* include/std/variant (__erased_ctor, __erased_assign, __erased_swap)
(__erased_hash): Remove constexpr specifier and qualify calls to
__ref_cast.
(__erased_dtor): Remove constexpr specifier and use _Destroy.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2837 bytes --]
commit 8a813292bd7170eb160b509122fc3bb388b87f12
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Jun 2 13:00:52 2017 +0100
PR libstdc++/80939 Remove unmeetable constexpr specifiers
PR libstdc++/80939
* include/std/variant (__erased_ctor, __erased_assign, __erased_swap)
(__erased_hash): Remove constexpr specifier and qualify calls to
__ref_cast.
(__erased_dtor): Remove constexpr specifier and use _Destroy.
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index b9824a5..e5fe9f9 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -44,6 +44,9 @@
#include <bits/invoke.h>
#include <ext/aligned_buffer.h>
#include <bits/parse_numbers.h>
+#include <bits/stl_iterator_base_types.h>
+#include <bits/stl_iterator_base_funcs.h>
+#include <bits/stl_construct.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
@@ -238,30 +241,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Various functions as "vtable" entries, where those vtables are used by
// polymorphic operations.
template<typename _Lhs, typename _Rhs>
- constexpr void
+ void
__erased_ctor(void* __lhs, void* __rhs)
- { ::new (__lhs) remove_reference_t<_Lhs>(__ref_cast<_Rhs>(__rhs)); }
+ {
+ using _Type = remove_reference_t<_Lhs>;
+ ::new (__lhs) _Type(__variant::__ref_cast<_Rhs>(__rhs));
+ }
template<typename _Variant, size_t _Np>
- constexpr void
+ void
__erased_dtor(_Variant&& __v)
+ { std::_Destroy(std::__addressof(__get<_Np>(__v))); }
+
+ template<typename _Lhs, typename _Rhs>
+ void
+ __erased_assign(void* __lhs, void* __rhs)
{
- auto&& __element = __get<_Np>(std::forward<_Variant>(__v));
- using _Type = std::remove_reference_t<decltype(__element)>;
- __element.~_Type();
+ __variant::__ref_cast<_Lhs>(__lhs) = __variant::__ref_cast<_Rhs>(__rhs);
}
template<typename _Lhs, typename _Rhs>
- constexpr void
- __erased_assign(void* __lhs, void* __rhs)
- { __ref_cast<_Lhs>(__lhs) = __ref_cast<_Rhs>(__rhs); }
-
- template<typename _Lhs, typename _Rhs>
- constexpr void
+ void
__erased_swap(void* __lhs, void* __rhs)
{
using std::swap;
- swap(__ref_cast<_Lhs>(__lhs), __ref_cast<_Rhs>(__rhs));
+ swap(__variant::__ref_cast<_Lhs>(__lhs),
+ __variant::__ref_cast<_Rhs>(__rhs));
}
#define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP, __NAME) \
@@ -283,11 +288,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#undef _VARIANT_RELATION_FUNCTION_TEMPLATE
template<typename _Tp>
- constexpr size_t
+ size_t
__erased_hash(void* __t)
{
return std::hash<remove_cv_t<remove_reference_t<_Tp>>>{}(
- __ref_cast<_Tp>(__t));
+ __variant::__ref_cast<_Tp>(__t));
}
// Defines members and ctors.
next reply other threads:[~2017-06-02 13:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-02 13:07 Jonathan Wakely [this message]
2017-06-02 19:19 ` Tim Shen via gcc-patches
2017-06-02 19:40 ` Tim Song
2017-06-05 16:49 ` Jonathan Wakely
2017-06-11 0:15 ` Tim Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170602130734.GA6233@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=t.canens.cpp@gmail.com \
--cc=timshen@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).