libstdc++: Deprecate non-standard std::vector<bool>::insert(pos) [PR104559]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 17 Feb 2022 17:37:42 +0000 (17:37 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 17 Feb 2022 23:44:25 +0000 (23:44 +0000)
The SGI STL and pre-1998 drafts of the C++ standard had a default
argument for vector<bool>::insert(iterator, const bool&) which was
remove by N1051. The default argument is still present in libstdc++ for
some reason. There are no tests verifying it as an extension, so I don't
think it has been kept intentionally.

This removes the default argument but adds an overload without the
second parameter, and adds the deprecated attribute to it. This allows
any code using it to keep working (for now) but with a warning.

libstdc++-v3/ChangeLog:

PR libstdc++/104559
* doc/xml/manual/evolution.xml: Document deprecation.
* doc/html/manual/api.html: Regenerate.
* include/bits/stl_bvector.h (insert(const_iterator, const bool&)):
Remove default argument.
(insert(const_iterator)): New overload with deprecated attribute.
* testsuite/23_containers/vector/bool/modifiers/insert/104559.cc:
New test.

libstdc++-v3/doc/html/manual/api.html
libstdc++-v3/doc/xml/manual/evolution.xml
libstdc++-v3/include/bits/stl_bvector.h
libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/104559.cc [new file with mode: 0644]

index 2608777..bbda6f5 100644 (file)
@@ -454,6 +454,9 @@ were deprecated for C++11.
 were deprecated for C++17.
 </p><p>
 Non-standard <code class="code">std::pair</code> constructors were deprecated.
+A non-standard default argument for
+<code class="code">vector&lt;bool&gt;::insert(const_iterator, const bool&amp;)</code>
+was deprecated.
 </p><p>
 The <code class="literal">bitmap</code>, <code class="literal">mt</code>, and <code class="literal">pool</code>
 options for <code class="option">--enable-libstdcxx-allocator</code> were removed.
index f5bc647..4923e8c 100644 (file)
@@ -1045,6 +1045,9 @@ were deprecated for C++17.
 
 <para>
 Non-standard <code>std::pair</code> constructors were deprecated.
+A non-standard default argument for
+<code>vector&lt;bool&gt;::insert(const_iterator, const bool&amp;)</code>
+was deprecated.
 </para>
 
 <para>
index 75f3881..d256af4 100644 (file)
@@ -1135,9 +1135,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       _GLIBCXX20_CONSTEXPR
       iterator
 #if __cplusplus >= 201103L
-      insert(const_iterator __position, const bool& __x = bool())
+      insert(const_iterator __position, const bool& __x)
 #else
-      insert(iterator __position, const bool& __x = bool())
+      insert(iterator __position, const bool& __x)
 #endif
       {
        const difference_type __n = __position - begin();
@@ -1149,6 +1149,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        return begin() + __n;
       }
 
+#if _GLIBCXX_USE_DEPRECATED
+      _GLIBCXX_DEPRECATED_SUGGEST("insert(position, false)")
+      iterator
+      insert(const_iterator __position)
+      { return this->insert(__position._M_const_cast(), false); }
+#endif
+
 #if __cplusplus >= 201103L
       template<typename _InputIterator,
               typename = std::_RequireInputIter<_InputIterator>>
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/104559.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/104559.cc
new file mode 100644 (file)
index 0000000..1121827
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-options "-Wdeprecated" }
+// { dg-do compile }
+// { dg-require-normal-mode "" }
+
+#include <vector>
+
+void
+test01()
+{
+  std::vector<bool> v;
+  v.insert(v.begin(), false);
+  v.insert(v.begin());  // { dg-warning "deprecated" }
+}