[Bug libstdc++/78595] Unnecessary copies in _Rb_tree
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jan 17 17:36:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78595
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Target Milestone|--- |8.0
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
A rejects-valid example that Tim Song provided in Bug 68869:
According to the standard ([map.modifiers]),
template <class P> pair<iterator, bool> insert(P&& x);
is equivalent to return emplace(std::forward<P>(x)), provided that
std::is_constructible<value_type, P&&>::value is true.
The following code does not compile when insert() is used, but does compile
when emplace() is used. The same issue also affects multimap.
#include <map>
#include <utility>
#include <type_traits>
#include <memory>
struct S {
operator std::pair<const int, int>() const && { return {}; }
};
static_assert(std::is_constructible<std::pair<const int, int>, S&&>::value,
"!!");
static_assert(std::is_constructible<std::pair<const std::unique_ptr<const int>,
int>, std::pair<std::unique_ptr<int>, int>&&>::value, "!!");
int main(){
std::map<std::unique_ptr<const int>, int> m;
std::map<int, int> m2;
m.insert(std::make_pair(std::make_unique<int>(), 1)); // Error
m2.insert(S()); // Error
m.emplace(std::make_pair(std::make_unique<int>(), 1)); // OK
m2.emplace(S()); // OK
}
More information about the Gcc-bugs
mailing list