early instantiation of defaulted copy constructor

Hello,

The following code fails to compile with Clang trunk:

template <class T, class U>
struct pair
{
T first;
U second;

pair\(\) : first\(\), second\(\) \{\}

pair\(const pair&amp;\) = default;

};

struct S
{
S() {}
S(const S&) = delete;
S(S&&) = default;
};

int main()
{
pair<int, S> p;
}

The errors are:

test.cpp:9:5: error: the parameter for this explicitly-defaulted copy constructor is const, but a member or base requires it to be
non-const
pair(const pair&) = default;
^
test.cpp:21:18: note: in instantiation of template class 'pair<int, S>' requested here
pair<int, S> p;
^

Why is clang trying to instantiate the copy constructor when it's never used?

Is there something about the copy constructor being defaulted that is causing
early instantiation? If I replace the defaulted copy constructor with an
explicit implementation:

pair(const pair& p) : first(p.first), second(p.second) {}

then I get no error, suggesting that clang is not trying to instantiate the
copy constructor.

As far as I'm aware, the defaulted implementation and the explicit
implementation should be the same in all respects, including time of
instantiation.

GCC compiles the original code without errors.

Thanks,
Nate

Thanks for the report! This issue was fixed over a week ago. Trunk clang accepts your code.

Hello,

The following code fails to compile with Clang trunk:

template <class T, class U>
struct pair
{
     T first;
     U second;

     pair() : first(), second() {}

     pair(const pair&) = default;
};

struct S
{
     S() {}
     S(const S&) = delete;
     S(S&&) = default;
};

int main()
{
     pair<int, S> p;
}

The errors are:

test.cpp:9:5: error: the parameter for this explicitly-defaulted copy
constructor is const, but a member or base requires it to be
       non-const
     pair(const pair&) = default;
     ^
test.cpp:21:18: note: in instantiation of template class 'pair<int, S>'
requested here
     pair<int, S> p;
                  ^

Thanks for the report! This issue was fixed over a week ago. Trunk
clang accepts your code.

Ok, cool! Will it be fixed in the 3.1 branch?

Thanks,
Nate

Yes.