<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66772>66772</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Defaulted method template specialization fails to compile
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nmakeenkov
</td>
</tr>
</table>
<pre>
Tried the example on godbolt with clang 16.0.0: https://gcc.godbolt.org/z/K1dGc55Tx
I have a template class with defaulted copy assignment operator in base declaration. I want to specialise it for some template parameter and get an error `error: definition of explicitly defaulted copy assignment operator`.
But I believe it's legal to define this operator.
The code is as follows (with g++ compiles and works as expected):
```
#include <iostream>
template <typename T>
class MyClass {
public:
MyClass() {}
MyClass& operator=(const MyClass& other) = default;
};
// Specialization
template <>
MyClass<int>& MyClass<int>::operator=(const MyClass& other) noexcept {
std::cout << "Specialized optor for int" << std::endl;
return *this;
}
int main() {
MyClass<double> obj1;
MyClass<double> obj2;
obj1 = obj2;
MyClass<int> obj3;
MyClass<int> obj4;
obj4 = obj3;
return 0;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVN1u4yoXfRpyszUWBseJL3yRn8mn6tO5On0BDDs2UwwW4DaZpz_CTpy200ojRbEDi732WuwsEYJuLWJN1nuyPq7EGDvna9uLF0T74l5XjVPX-tlrVBA7BLyIfjAIzkLrVONMhDcdO5BG2BbyMqMZJXwHXYxDIHxH2ImwUytldoNnzreEnX4Tdvp_rv4n1-vnC6FHQnfz9xN04hVBQMR-MCJiKh3CzKLwLEYTUYF0wxXm7nu0EdyAXkTnQVtoREBQKI3wImpnM3iCN2EjRAdhQKmF0QFBRzg7D8H1-CAbhBc9RvQgrIIWIwgL6L3zQEo6vSR5Cs_a6lQc3BnwMhgtdTTXv-iQlDSbpe7HCE_QoNH4mtohbBPAYCtM6nSiQIidDsvZ7L1Tzx2CdApBBxAB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