https://bugs.llvm.org/show_bug.cgi?id=48619
Bug ID: 48619
Summary: Allow std::vector::insert to compile when elements
have a deleted assignment operator
Product: libc++
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Create a class `X` which is copy-constructible but not copy-assignable
```
struct X {
X();
X(const X&);
X& operator=(const X&) = delete; // !!
X(X&&) noexcept;
X& operator=(X&&) noexcept;
int data = 54;
};
```
Have vectors of X `a` and `b`. Try to add all elements of b at the front of a:
```
void add_to_front(std::vector<X>& a, const std::vector<X>& b) {
a.insert(a.begin(), b.begin(), b.end());
}
```
Live demo: https://godbolt.org/z/K1WT8n
It doesn't compile. My guess is that code which will never get invoked, still
needs to compile (or, worse yet, copy assignment does get invoked?!)
The only way to achieve the desired behavior efficiently is to use a custom
vector implementation. There is a stackoverflow question which has some *worse*
workarounds:
https://stackoverflow.com/questions/65489039/how-to-efficiently-insert-multiple-copy-constructible-but-not-copy-assignable-el
This does compile and work on msvc, so a compile-time check for the
copy-assignment code is possible.
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs