If the parameter is not lvalue-convertible to bool then the current code
will fail to compile. The parameter should be forwarded to restore the
original value category.
libstdc++-v3/ChangeLog:
* include/bits/stl_bvector.h (emplace_back, emplace): Forward
parameter pack to preserve value category.
* testsuite/23_containers/vector/bool/emplace_rvalue.cc: New
test.
#endif
emplace_back(_Args&&... __args)
{
- push_back(bool(__args...));
+ push_back(bool(std::forward<_Args>(__args)...));
#if __cplusplus > 201402L
return back();
#endif
_GLIBCXX20_CONSTEXPR
iterator
emplace(const_iterator __pos, _Args&&... __args)
- { return insert(__pos, bool(__args...)); }
+ { return insert(__pos, bool(std::forward<_Args>(__args)...)); }
#endif
protected:
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+#include <vector>
+
+struct S
+{
+ explicit operator bool() &&;
+};
+
+void
+test_emplace_back()
+{
+ S s;
+ std::vector<bool> v;
+ v.emplace_back(std::move(s));
+}
+
+void
+test_emplace()
+{
+ S s;
+ std::vector<bool> v;
+ v.emplace(v.begin(), std::move(s));
+}