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

    <tr>
        <th>Summary</th>
        <td>
            Incorrect and stateful access control for user-defined conversion in function template default argument initialization
        </td>
    </tr>

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

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

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

<pre>
    Clang accepts-invalid:
```c++
struct B { friend struct A; private: B(int); };
template<class T> int f(T = 0);
struct A { A() { int i = f<B>(); } };
```
Per http://eel.is/c++draft/temp.inst#12.sentence-1 access control should be the same as for a function template specialization adjacent to `f`; the friendship of `A` is irrelevant. MSVC and gcc get this right, although gcc weirdly accepts-invalid if the ctor is `B()` and the default argument initializer is `{}`.

Worse, clang correctly rejects if the caller is not a friend:
```c++
struct B { friend struct A; private: B(int); };
template<class T> int f(T = 0);
int i = f<B>(); // error: calling a private constructor of class 'B'
```
but if the friend call is moved first it accepts, indicating that the instantiated default argument has been remembered, which would be fine if it didn't use `A`'s access control.
```c++
struct B { friend struct A; private: B(int); };
template<class T> int f(T = 0);
struct A { A() { int i = f<B>(); } };
int i = f<B>();
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU2P4zYM_TXKhYjhyE48PvgQZzZADwUKdNGeFYmyuZClQKIz2P76QkoyxU63e-phASMfokTyPT49q5Ro8oiD2I9i_7pRK88hDqgVL2vcXIL5Opyc8hMorfHKaUv-phwZ0RxF_SrqozjU90cLOeanrCaOq2YYQXQj2EjoDTzWjqIZ4RrpphhFc4RRyBfyLGSfA6J7Fc0jCeNydWXXSTuVEnwWzScgz2CFfPkMonmF-n7um6rHUvUo5IuQffmdz1DZb0VzGkXz6R58VPym6jug-9_fMMLMfM2A5VnIM6KrKAl5fgA2UVkW8py7rcgnFrLZySqhZ_Qat7tCXUqgg-cYHKQ5rM7ABYFnhKQWBJXAhggK7Oo1U_DwxA7pipqUo79UWVfmi9LoGTiAONQ299mMJdOd5jTTFYLNwQwFKAHFiA5vynMFv_7-xwmUNzBpDRMy8EwJIk0zC3kC5XgO6zSX8BtSNO7rx9ED2VJPc4g5vTjU44POQ11y56hBq1bHoOK0Lrlh8sQFCD5PiW7MxB_q6sF8-fwzxIS5F110p0OMqNl9hYhfUHN6L6-cu6fygTN1Bf5Pqcsfyq-ICjDGEHPZDIvyfXv2knVzbzHEPNh7SSG7Ucjuu5K9rPwk6QExJ81MLeGGBizFxED8HGwmm7whrThX5llxOZzFrDyTYjT_nuesElwQPURccLlgRJMTvc2kZ3h7StySx9wMMRgyXsiOYU34lKeQXfpwP6qfb37_i6_8YO8HxBszNKZverXBYXd4kV0j5b7bzENzkVJbqaxt213bN_0etdW92stO9rbuNzTIWjZ1K_t613RNV3XS7HrTtm3T4U7ZXrQ1Lopc5dxtqUKcNpTSisNBtm27ceqCLpV3gZQe36AEhZT51RCHfGZ7Wack2tpR4vRPFiZ2OPziH7e1uEBixWhX99H_stOtCePWYFaHyYEbxpTtjfx3LPC_raR44maNbsgWnd49eiKe10ulwyLkOTf5-NpeY8gmIuS5QMs2XqD_HQAA__9RgCbD">