libstdc++: Reduce the size of an unbounded iota_view
authorPatrick Palka <ppalka@redhat.com>
Mon, 28 Sep 2020 15:54:57 +0000 (11:54 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 28 Sep 2020 15:54:57 +0000 (11:54 -0400)
libstdc++-v3/ChangeLog:

* include/std/ranges (iota_view::_M_bound): Give it
[[no_unique_address]].
* testsuite/std/ranges/iota/iota_view.cc: Check that an
unbounded iota_view has minimal size.

libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc

index ed04fa0001d1c093f06c173f4c383796d8e3cd84..964a2b616a6fcfd185b72b2e2a16ffd557c0110b 100644 (file)
@@ -511,7 +511,7 @@ namespace ranges
       };
 
       _Winc _M_value = _Winc();
-      _Bound _M_bound = _Bound();
+      [[no_unique_address]] _Bound _M_bound = _Bound();
 
     public:
       iota_view() = default;
index 65d166fbd3b188bbbc0ef87a5f7940822df045e2..8a33e10a093c368e19facbc941fbdf71aa1383dd 100644 (file)
@@ -77,6 +77,9 @@ test04()
   VERIFY( it == v.end() );
 }
 
+// Verify we optimize away the 'bound' data member of an unbounded iota_view.
+static_assert(sizeof(std::ranges::iota_view<char>) == 1);
+
 int
 main()
 {