<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54865>54865</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            defaulted operator== cannot use protected operator== in parent class
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          AMDG2
      </td>
    </tr>
</table>

<pre>
    A class cannot default `operator==` if parent class `operator==` is protected. The compiler complains that `Base::operator==` is protected and can only be used on object of type `Child`, see the following example (https://godbolt.org/z/9c8drEccv):

```
struct Base {
  protected:
    Base() = default;
    bool operator==(const Base& other) const = default;
};

struct Child : Base {
    int         i = 0;
    Child() = default;
    bool operator==(const Child& other) const = default;
};

int main() 
{
    Child a1;
    Child b1;
    return a1 != b1;
}
```

There is probably implementation detail that makes the defaulted operator== unable to access base-class, but this behavior is surprising and unfortunate. We can clearly see that it works fine for constructor, so there is inconsistency.

Additionally this make it very difficult to use defaulted operator== when you have a common base class that should not be comparable. See this other example: https://godbolt.org/z/vnb6oE31M.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVE1z2jAQ_TXmshOP8QcxBx8gJD311M70LNlrrEZIjCRD6a_vrgwlIUk7E0bYlrTafW_1dqXtTs0KWi28h1YYYwN02ItRB0gWmd2jE8G6pNjwWGSgetgLhyacz7xv5GHvbMA2YJfC9wGhtbu90ujihxbKeAiDiDHWwmNSrGj82xEI0zFEsEafQCKMnhYtzeVPMgDbQzjtkV0-DEp39E7yB_CIFAqht1rbozJbwF-CMJBhXg8h7D0Hz59obG0nrQ6pdVua_ab_sq0799i2hyRfslm2SbLLk9xPI059cCOBYDKQ3K-nRbii_3sa6Bcp5zU5BSJ6SXhSrK8m0loNNwnJ69YaH87HF2CJl2Mn0_J7rpL7zfX7JdCYIjqyegMZQNHtXn4qus1eYZvS-3n85_OfJMDodqSgC4Cz2S0-EPO3oEG-XnQYRmfIlMQw5_Av9jnyezc9PUnUDs_6lEKSIhWLakeVIYIiVXYYhNKTynfiGX1U4ZkeC_dVbmA05ISUakG0LVJhSbqWu1hjrGI5BjpP4SQO4qCs49B-dHunPGuaa2M0vXWBHAVM4QfGWmk1CkfgpiogKCrA0bpnD70yXBRuyj1rgrBwvVgGOnFThjeVD2jaU_qS_qrrFNMUmpxHYMyRvR_QnaBTfa9abiJEiOr0Y97HAQ2c7AhEC0Fwf9hR9pj9ucNE2H6wI10ftyc5dRPhOGEpfIvMCEAU06W4Wdj_K-6DkQv7WMy_prOuKbplsRSzoILG5kO05w7JjK596cZGmVcdcjY63dxAUWEYZUosaKL14fK6I5_cymiqvB-Rbv6pKutFNRuaVhRdjlVRLjK8LzJR1fkS-6IUpajLPKtmWkjUvkmqdZLnBo8QXdB3Um1mqsmzPM_KeZ7VVVnOUxRlX8-FLJZVT65kUmZIRaVTxsE5mrkmQpLj1tOmJhH46ybxUluDGMORfzGGwbpm9XXzJZ_FwE0E_gemi__L">