]> gcc.gnu.org Git - gcc.git/commitdiff
Enforce LWG DR 2566 requirement for container adaptors
authorJonathan Wakely <jwakely@redhat.com>
Thu, 14 Feb 2019 14:10:12 +0000 (14:10 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 14 Feb 2019 14:10:12 +0000 (14:10 +0000)
Although there is no good use for stack<int, deque<double>> or similar
types with a mismatched value_type, it's possible somebody is doing that
and getting away with it currently. This patch only enforces the new
requirement for C++17 and later. During stage 1 we should consider
enforcing it for C++11 and C++14.

* doc/xml/manual/intro.xml: Document LWG 2566 status.
* include/bits/stl_queue.h (queue, priority_queue): Add static
assertions to enforce LWG 2566 requirement on value_type.
* include/bits/stl_stack.h (stack): Likewise.

From-SVN: r268877

libstdc++-v3/ChangeLog
libstdc++-v3/doc/xml/manual/intro.xml
libstdc++-v3/include/bits/stl_queue.h
libstdc++-v3/include/bits/stl_stack.h

index c20c4e1acd49abc710b628fc0ecf2b6d22df8625..8cedc38c1a4cd564769784fe25747cbf9317a361 100644 (file)
@@ -1,5 +1,10 @@
 2019-02-14  Jonathan Wakely  <jwakely@redhat.com>
 
+       * doc/xml/manual/intro.xml: Document LWG 2566 status.
+       * include/bits/stl_queue.h (queue, priority_queue): Add static
+       assertions to enforce LWG 2566 requirement on value_type.
+       * include/bits/stl_stack.h (stack): Likewise.
+
        PR middle-end/89303
        * testsuite/20_util/enable_shared_from_this/89303.cc: New test.
 
index 71050a0cebc45c9738f8b2bce0b2eb9b8e17be4e..2a3231f4eb4985bcc97f84ec97944520c7b1955a 100644 (file)
@@ -1120,11 +1120,18 @@ requirements of the license of GCC.
     ill-formed.
     </para></listitem></varlistentry>
 
+    <varlistentry xml:id="manual.bugs.dr2537"><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&DR;#2537">2537</link>:
+       <emphasis>Requirements on the first template parameter of container adaptors
+       </emphasis>
+    </term>
+    <listitem><para>Add static assertions to enforce the requirement.
+    </para></listitem></varlistentry>
+
     <varlistentry xml:id="manual.bugs.dr2583"><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&DR;#2583">2583</link>:
        <emphasis>There is no way to supply an allocator for <code>basic_string(str, pos)</code>
        </emphasis>
     </term>
-    <listitem><para>Add new constructor
+    <listitem><para>Add new constructor.
     </para></listitem></varlistentry>
 
     <varlistentry xml:id="manual.bugs.dr2684"><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&DR;#2684">2684</link>:
index 6d092c9bbfe33e9d2b4ea6c413913745f0f026c2..1eb56810edc987ae7b5b733a823cc73a93a35b68 100644 (file)
@@ -118,7 +118,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _Alloc>
        using _Uses = typename
          enable_if<uses_allocator<_Sequence, _Alloc>::value>::type;
-#endif
+
+#if __cplusplus >= 201703L
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 2566. Requirements on the first template parameter of container
+      // adaptors
+      static_assert(is_same<_Tp, typename _Sequence::value_type>::value,
+         "value_type must be the same as the underlying container");
+#endif // C++17
+#endif // C++11
 
     public:
       typedef typename _Sequence::value_type           value_type;
@@ -451,17 +459,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _Alloc>
        using _Uses = typename
          enable_if<uses_allocator<_Sequence, _Alloc>::value>::type;
-#endif
+
+#if __cplusplus >= 201703L
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 2566. Requirements on the first template parameter of container
+      // adaptors
+      static_assert(is_same<_Tp, typename _Sequence::value_type>::value,
+         "value_type must be the same as the underlying container");
+#endif // C++17
+#endif // C++11
 
     public:
       typedef typename _Sequence::value_type           value_type;
-      typedef typename _Sequence::reference             reference;
-      typedef typename _Sequence::const_reference         const_reference;
-      typedef typename _Sequence::size_type             size_type;
-      typedef          _Sequence                           container_type;
+      typedef typename _Sequence::reference            reference;
+      typedef typename _Sequence::const_reference      const_reference;
+      typedef typename _Sequence::size_type            size_type;
+      typedef          _Sequence                       container_type;
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // DR 2684. priority_queue lacking comparator typedef
-      typedef         _Compare                             value_compare;
+      typedef         _Compare                         value_compare;
 
     protected:
       //  See queue::c for notes on these names.
index e8443a78a05a523f911fd1fe0a44bf476b2a30b8..28faab2e8716ce8a5cc1e77e64118b86754e44ec 100644 (file)
@@ -120,7 +120,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _Alloc>
        using _Uses = typename
          enable_if<uses_allocator<_Sequence, _Alloc>::value>::type;
-#endif
+
+#if __cplusplus >= 201703L
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 2566. Requirements on the first template parameter of container
+      // adaptors
+      static_assert(is_same<_Tp, typename _Sequence::value_type>::value,
+         "value_type must be the same as the underlying container");
+#endif // C++17
+#endif // C++11
 
     public:
       typedef typename _Sequence::value_type           value_type;
This page took 0.079519 seconds and 5 git commands to generate.