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

    <tr>
        <th>Summary</th>
        <td>
            Clang fails to consider default arguments reachable at the instantiation context
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++,
            clang:frontend,
            miscompilation,
            accepts-invalid,
            rejects-valid,
            diverges-from:gcc,
            diverges-from:msvc,
            diverges-from:edg
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          hubert-reinterpretcast
      </td>
    </tr>
</table>

<pre>
    When compiling the following, Clang does not consider the default arguments provided by the declaration marked `(A)`: https://godbolt.org/z/8Gxb3fvPz

The Clang behaviour is inconsistent with CWG's interpretation (during the 2025-04-11 teleconference) of https://wg21.link/dcl.fct.default#9.sentence-9:

> When an overload set contains a declaration of a function that inhabits a scope _S_, any default argument associated with any reachable declaration that inhabits _S_ is available to the call.

That is, although no argument-dependent lookup takes place for the case in question, the default arguments in play are extended to ones provided by redeclarations of the functions that were candidates in the template definition context.

### Source (`<stdin>`)
```cpp
constexpr int f(int *, int) { return 42; }
constexpr int f(void *) { return 13; }

template <typename T>
constexpr int g() {
 return f(T{});
}

constexpr int f(int *, int = 0);  // (A)

static_assert(g<int *>() == 42, "");
```

### Compiler invocation
```
clang++ -fsyntax-only -Wall -Wextra -pedantic -std=c++11 -xc++ -
```

### Actual output
```
<stdin>:11:15: error: static assertion failed due to requirement 'g<int *>() == 42':
   11 | static_assert(g<int *>() == 42, "");
      | ^~~~~~~~~~~~~~~~
<stdin>:11:26: note: expression evaluates to '13 == 42'
 11 | static_assert(g<int *>() == 42, "");
      | ~~~~~~~~~~~^~~~~
1 error generated.
```

### Expected output
(Clean compile)

### Compiler version info (`clang++ -v`)
```
clang version 21.0.0git (https://github.com/llvm/llvm-project.git 9466cbdf29306b2595303dac5b62b54cf71841b4)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VkFv4zoO_jXKhXBgy07iHHJw02awtwVmgDkWskTb2iqSnySn6Tvsb19QTtJJp_MeFrNbGE1ikdT3kR8piRB0bxF3bPXAVo8LMcXB-d0wtehj5lHbiH70GKUIcdE69bb7PqAF6Y6jNtr2EAeEzhnjXrXtGd_D3gjbg3IYwLoI0tmgFfpkqLATk4kgfD8d0cYAo3cnrVBB-3axkEZ4EbWzcBT-BRWwdc543TC-pW9lA0OMY2Blw_iB8UPvVOtMXDrfM374k_FD_eXclt3pn3-yvGF5823AC6gWB3HSbvKgA2iboIWINsKrjgPsv39hfEMrF9IzDMZrNfkrV57zVZZXWVFARIPS2Q49WomMb8F1H8C99rxYGm1fGD8oaZadjMtLEhgvt8uANpJztiWXBJeVT5ByLCy4E3rjhIKAKZNRaBtA3GXJdSCgm6xMv-IgImg7iFZHsgzSjQjPX5-pNMK-_VQCECE4qUVENWeBjDwKOYjW3NfjPvbz12dKozgJbZJpdClBUhizvGaeHELa2sTBTf0A1t22zhSOaBWBMM69TCNE8YIBRiMkicpf4gUEbeGPCQPBoGifa0lbcn0D4RHwHCm0IlTO4r3QPP5AK1AGk4ovOQwz0Vf0tLlVWomIKTpZRTyORsS0v7Y6JYYqg-d4Yc14OT_w1U1eIgkoKXcfotKWlU9J0VsyXefzI8eR5Q0JMuJ59CRB6Biv6ZPxhjhrG0libPMAHuPkLVSclQ_ANo-fup6cVrPvnVNRvjuxvLnRYeU-vo1oxRHhG2H8GLMnGnMsljfXcLTTN3q1eSRKJa3dgv8dH2DlI-SzH8DcMXDt9RQhUA_KZxEC-sh43bNyf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