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

    <tr>
        <th>Summary</th>
        <td>
            Bogus error when using `__reference_converts_from_temporary` in default template argument
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend
      </td>
    </tr>

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

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

<pre>
    We ran into this with an `std::function` (libstdc++ 13) returning an object with protected copy constructor. It boils down to this:

```c++
class X {
protected:
    X(const X&);
};

static_assert(!__reference_converts_from_temporary(X, X));

template<typename A, typename B,
         bool Dangle = __reference_converts_from_temporary(A, B)>
static void test();

using Result = decltype(test<X, X>());
```
produces:
```
bug.cpp:9:24: error: calling a protected constructor of class 'X'
    9 |          bool Dangle = __reference_converts_from_temporary(A, B)>
      | ^
```
Replacing either `A` or `B` by `X` doesn't make the error go away. Interestingly, if we define `test`, for example with an empty body, and do a full instantiation, then the error appears if the instantiation is implicit, but not if it's explicit:
```c++
template<typename A, typename B,
 bool Dangle = __reference_converts_from_temporary(A, B)>
static void test() {} // <-- Added an empty body.

template void test<X, X>(); // No error.

void f() {
    test<X, X>(); // Error.
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VcuOqzgTfprKptQRGAJhwSKXbuls_sXZ_L2LjCmIZ4yN7KL75O1HBjqdntFoejETIaXAVV_dvirLEHRviWrYHWF33siJr87XUnpnx0ldyfOmce2t_j-hlxa1ZYd81QHfNV9RWoQiCdxCdoDs0E1WsXYWigRB7I1uArcKxBHEEdMMRIWeePJW2z7auuY3UrxAjd4xKaYWlRtvqJwN7CfFzm_xB2PjtAnYuneLawTRZTI_RbI8qydIDsrIEPAVoYxvd-jFBBHxFcR-dhGlAkQFWdSE8rwKySGwZK0uMgTyDGIPIr1cPHXkySq6KGffyHO4dN4NF6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