Re: [Patch] Remove variant, variant<T&> and variant<>

2016-11-15 Thread Tim Shen
On Tue, Nov 15, 2016 at 11:31 AM, Jonathan Wakely  wrote:
> On 15/11/16 12:08 +, Jonathan Wakely wrote:
>>
>> On 12/11/16 12:11 -0800, Tim Shen wrote:
>>>
>>> At Issaquah we decided to remove the supports above.
>>
>>
>> OK with a suitable ChangeLog, thanks.
>
>
> I've adjusted your ChangeLog entry to fit under 80 columns with TAB
> set to 8 spaces. I've also adjusted the pretty printer test that was
> using variant.

Thanks! This is how tabstop=2 people have a different view of world
from the rest of us. :)

And I keep forgetting running the whole testsuite. Sorry!

>
> Tested x86_64-linux, committed to trunk.
>



-- 
Regards,
Tim Shen


Re: [Patch] Remove variant, variant<T&> and variant<>

2016-11-15 Thread Jonathan Wakely

On 15/11/16 12:08 +, Jonathan Wakely wrote:

On 12/11/16 12:11 -0800, Tim Shen wrote:

At Issaquah we decided to remove the supports above.


OK with a suitable ChangeLog, thanks.


I've adjusted your ChangeLog entry to fit under 80 columns with TAB
set to 8 spaces. I've also adjusted the pretty printer test that was
using variant.

Tested x86_64-linux, committed to trunk.

commit ab5b0b5d8618cd03e4d21a37b782d2726361bde2
Author: Jonathan Wakely 
Date:   Tue Nov 15 19:21:02 2016 +

Adjust pretty printer test for variant

	* testsuite/libstdc++-prettyprinters/cxx17.cc: Adjust test for
	variant.

diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc
index bc9b26a..96be8c7 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc
@@ -86,8 +86,8 @@ main()
 // { dg-final { note-test v3 {std::variant [index 1] = {3}} } }
   variant v4{ str };
 // { dg-final { note-test v4 {std::variant [index 2] = {"string"}} } }
-  variant vref{str};
-// { dg-final { note-test vref {std::variant &> [index 0] = {"string"}} } }
+  variant vref{str};
+// { dg-final { note-test vref {std::variant [index 0] = {"string"}} } }
 
   map m{ {1, "one"} };
   map::node_type n0;


Re: [Patch] Remove variant, variant<T&> and variant<>

2016-11-15 Thread Jonathan Wakely

On 12/11/16 12:11 -0800, Tim Shen wrote:

At Issaquah we decided to remove the supports above.


OK with a suitable ChangeLog, thanks.



[Patch] Remove variant, variant<T&> and variant<>

2016-11-12 Thread Tim Shen
At Issaquah we decided to remove the supports above.

Bootstrapped and tested on x86_64-linux-gnu.

Thanks!


-- 
Regards,
Tim Shen
Index: libstdc++-v3/include/std/variant
===
--- libstdc++-v3/include/std/variant	(revision 242337)
+++ libstdc++-v3/include/std/variant	(working copy)
@@ -136,42 +136,11 @@
 struct __reserved_type_map_impl
 { using type = add_cv_t<__reserved_type_map<_From, _To>>; };
 
-  // Stores a reference alternative as a... well, reference.
-  template
-struct _Reference_storage
-{
-  static_assert(is_reference_v<_Reference>,
-		"BUG: _Reference should be a reference");
-
-  _Reference_storage(_Reference __ref) noexcept : _M_storage(__ref) { }
-
-  operator _Reference() noexcept
-  { return static_cast<_Reference>(_M_storage); }
-
-  _Reference _M_storage;
-};
-
-  // Stores a void alternative, because it is not a regular type.
-  template
-struct _Void_storage { };
-
-  // Map from the alternative type to a non-qualified storage type.
-  template
-struct __storage_type
-{ using type = _Alternative; };
-
+  // This abstraction might be useful for future features,
+  // e.g. boost::recursive_wrapper.
   template
-struct __storage_type<_Alternative,
-			  enable_if_t>>
-{ using type = _Reference_storage<_Alternative>; };
+using __storage = _Alternative;
 
-  template
-struct __storage_type<_Alternative, enable_if_t>>
-{ using type = _Void_storage<_Alternative>; };
-
-  template
-using __storage = typename __storage_type<_Type>::type;
-
   template>
 struct _Uninitialized;
 
@@ -201,37 +170,15 @@
 	  _M_storage;
 };
 
-  // Reverse mapping of __storage_type.
-  template
-struct __alternative_type
-{
-  static_assert(!is_reference_v<_Storage_type>,
-		"BUG: _Storage_type should not be reference");
-  using type = _Storage_type;
-};
-
-  template
-struct __alternative_type<_Reference_storage<_Reference>>
-{ using type = _Reference; };
-
-  template
-struct __alternative_type<_Void_storage<_Void>>
-{ using type = _Void; };
-
   // Given a qualified storage type, return the desired reference.
-  // The qualified storage type is supposed to carry the variant object's
-  // qualifications and reference information, and the designated alternative's
-  // storage type.
-  // Returns the qualification-collapsed alternative references.
-  //
-  // For example, __get_alternative<_Reference_storage&> returns int&.
+  // For example, variant&& stores the int as __storage, and
+  // _Qualified_storage will be __storage&&.
   template
 decltype(auto)
 __get_alternative(void* __ptr)
 {
   using _Storage = decay_t<_Qualified_storage>;
-  using _Alternative = typename __alternative_type<_Storage>::type;
-  return __reserved_type_map<_Qualified_storage, _Alternative>(
+  return __reserved_type_map<_Qualified_storage, _Storage>(
 	*static_cast<_Storage*>(__ptr));
 }
 
@@ -969,6 +916,13 @@
 	variant<_Types...>>
 {
 private:
+  static_assert(sizeof...(_Types) > 0,
+		"variant must have at least one alternative");
+  static_assert(!(std::is_reference_v<_Types> || ...),
+		"variant must have no reference alternative");
+  static_assert(!(std::is_void_v<_Types> || ...),
+		"variant must have no void alternative");
+
   using _Base = __detail::__variant::_Variant_base<_Types...>;
   using _Default_ctor_enabler =
 	_Enable_default_constructor<
@@ -1264,11 +1218,6 @@
 __get_storage(_Vp&& __v);
 };
 
-  // To honor algebraic data type, variant<> should be a bottom type, which
-  // is 0 (as opposed to a void type, which is 1). Use incomplete type to model
-  // bottom type.
-  template<> class variant<>;
-
   template
 variant_alternative_t<_Np, variant<_Types...>>&
 get(variant<_Types...>& __v)
Index: libstdc++-v3/testsuite/20_util/variant/compile.cc
===
--- libstdc++-v3/testsuite/20_util/variant/compile.cc	(revision 242337)
+++ libstdc++-v3/testsuite/20_util/variant/compile.cc	(working copy)
@@ -55,7 +55,6 @@
 {
   static_assert(is_default_constructible_v>, "");
   static_assert(is_default_constructible_v>, "");
-  static_assert(!is_default_constructible_v>, "");
   static_assert(!is_default_constructible_v>, "");
   static_assert(is_default_constructible_v>, "");
 
@@ -124,14 +123,6 @@
   variant a(allocator_arg, alloc);
   static_assert(!is_constructible_v, "");
   {
-variant b(allocator_arg, alloc, a);
-static_assert(!is_constructible_v, "");
-  }
-  {
-variant b(allocator_arg, alloc,