Suppose you have the following class:
struct A { A () {} A (A &) = delete; }; int main() { std::pair<A, int> p1; return 0; }
The following code will not be able to compile (using -std=c++11 with g++ ) with the following error:
/usr/include/++/5/bits/stl_pair.h: When creating 'struct std :: pair:
test.cpp: 13: 23: required from here
/usr/include/++/5/bits/stl_pair.h: 127: 17: error: 'constexpr std :: pair <_T1, _T2> :: pair (const std :: pair <_T1, _T2> &; ) [with _T1 = A; _T2 = int] is declared to accept a const reference, but an implicit declaration will accept a non-constant
constexpr pair(const pair&) = default;
According to the error message, I would suggest that this is because it is not possible to create a default copy constructor due to the const qualifier in the std::pair argument.
I could understand why this would not compile without = delete , because it is impossible to create a copy constructor that takes the std::pair const& parameter.
But with = delete I would expect the compiler to not create such a constructor, because it cannot (as far as I understand). In fact, this copy constructor is deleted, as shown in this code snippet:
std::pair<A, int> p1; decltype(p1) p2(p1);
What fails:
test.cpp: 11: 23: error: using the remote function 'constexpr std :: pair <_T1, _T2> :: pair (const std :: pair <_T1, _T2> &) [with _T1 = A; _T2 = int]
decltype(p1) p2(p1);
Basically, my question is: why can't the compiler create an instance of the instantiated remote copy of std::pair ?