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

    <tr>
        <th>Summary</th>
        <td>
            [C++20] [Modules] Incorrect Reachability for default argument
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++20,
            clang:modules
      </td>
    </tr>

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

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

<pre>
    The example in [[module.reach]p4-ex1](http://eel.is/c++draft/module.reach#example-1) should be rejected at the last statement. However, it is accepted now: https://github.com/llvm/llvm-project/blob/b1d5af81249dc7e5697faf9ee33f86012ccd8668/clang/test/CXX/module/module.reach/ex1.cpp#L42-L43

The segmented code would be:

```C++
// M.cppm
export module M;
export import :A;
import :B;
B b2;
export void f(B b = B());

//--- X.cppm
export module X;
import M;
B b3; // expected-error {{definition of 'B' must be imported from module 'M:B' before it is required}} 
// FIXME: We should emit an error for unreachable definition of B.
void g() { f(); }
```

The definition of B is unreachable in X.cppm expectedly. This is verified in the above test line `B b3`. However, when we call `f()` in X.cppm, no diagnostic is emitted. I suspect the reason should be currently clang would evaluate the default argument in the callee position instead of the caller position.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVMGOozgQ_Rq4lIKMCRAOHDqdbW1Lk8tqpM3VQAFeGczYJun--y1Dku5ktIeVShjb5ar3nqtc6eaz_Nkj4IcYJoUgRwjSPdmgm1lhZFDUfZAepu0GP2L6Cfiud24KkpeAv5Ehqkha-qkDvidrjGgdTR_O8-QafxMHvADb61k1UCEY_Adrhw0IB45gKGEdWCccDji6CP7UFzyjCfgrSAfSgqhrnPyBUV8IA3gs9g6mk66fq6jWA02UOt-GzWS0T0TTSunKD3GTinYX823R1DmmWZG3oi0Qk6TdZSzmdd3ssmzniSkxdjQ6tD7A6-l0p_cbzzcSKaqniRj_2PLNj20SsEP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