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

    <tr>
        <th>Summary</th>
        <td>
            [C++20] [Modules] linker error with a `static constexpr` lambda in a templated class
        </td>
    </tr>

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

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

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

<pre>
    While testing the libc++ std module I ran into linker errors in several tests. They all seem to be the same issue.

Tested with a recent Clang-17 build with the libc++ test 
`libcxx/test/std/thread/thread.stoptoken/stopcallback/cons.const.token.pass.cpp`
modified to use `import std;` instead of using includes. This gives the following output
```
# command stderr:
/usr/bin/ld: /tmp/lit-tmp-htiaxlnf/cons-6e2fbe.o: in function `std::__1::__atomic_unique_lock<unsigned int, 2u>::__lock[abi:v170000]()':
cons.const.token.pass.cpp:(.text._ZNSt3__120__atomic_unique_lockIjLj2EE6__lockB7v170000Ev[_ZNSt3__120__atomic_unique_lockIjLj2EE6__lockB7v170000Ev]+0x24): undefined reference to `std::__1::__atomic_unique_lock<unsigned int, 2u>::__set_locked_bit[abi:v170000]'
/usr/bin/ld: /tmp/lit-tmp-htiaxlnf/cons-6e2fbe.o: in function `std::__1::atomic<unsigned int>& std::__1::__atomic_unique_lock<unsigned int, 2u>::__atomic_unique_lock[abi:v170000]<std::__1::__stop_state::__add_callback[abi:v170000](std::__1::__stop_callback_base*)::{lambda(unsigned int)#1} const&>(std::__1::__stop_state::__add_callback[abi:v170000](std::__1::__stop_callback_base*)::{lambda(unsigned int)#1} const&)':
cons.const.token.pass.cpp:(.text._ZNSt3__120__atomic_unique_lockIjLj2EEC2B7v170000IRKZNS_12__stop_state14__add_callbackB7v170000EPNS_20__stop_callback_baseEEUljE_EERNS_6atomicIjEEOT_[_ZNSt3__120__atomic_unique_lockIjLj2EEC2B7v170000IRKZNS_12__stop_state14__add_callbackB7v170000EPNS_20__stop_callback_baseEEUljE_EERNS_6atomicIjEEOT_]+0x2e): undefined reference to `std::__1::__atomic_unique_lock<unsigned int, 2u>::__set_locked_bit[abi:v170000]'
/usr/bin/ld: /llvm/build/generic-module-std-cxx23/test/std/thread/thread.stoptoken/stopcallback/Output/cons.const.token.pass.cpp.dir/t.tmp.exe: hidden symbol `_ZNSt3__120__atomic_unique_lockIjLj2EE16__set_locked_bitB7v170000E' isn't defined
/usr/bin/ld: final link failed: bad value
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

error: command failed with exit status: 1
```
This seems to point to this lamba
https://github.com/llvm/llvm-project/blob/main/libcxx/include/__stop_token/atomic_unique_lock.h#L132
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVk2P2zYT_jX0ZWBBIi15ffDB9trA4s27KbIpWuQiUOLY4i5FKiLlOP--GEn25sMbpG0atIAhS-RwZp754DzSe32wiEuWrhnnm6qT9r3-vVswzll6O5FdqFy7rF2rpA04KZz6uPyt0gYhoA_aHiBUCEYXJeNrxtfgg4Laqc4g3EErLWgbHBhtn7AFbFvXetAWPB6xlabX4iN4W-FHkMaAR6whOCiwV-xljaC97zBi8S2LV8PzLfqACj7oUIGEFku0ATZG2sM0mUPRaTNufuEcWYNRURbTxunE-I6WGd_5oOijalE-v0Q-uCa4J7S9hGtKaUwhyyfGd6WzPqJHiHqJqJHeR2XTsCwerNRO6b1GRZA6j8CyWNeNawPFiYk1y2LQ1geUCtweOk8R1bY0ncI-LNrDQR_R90j2zhj3gURcF5ouXJCMv-GTCyhdXUuryAi2LROr89au8y3ju0ITGqOYWAEhrRv61GEa6mZaBS1Pxu5HgNMM-b7AyJGwtrDvbBm0s4SlB7FiYpXnyflFBlfrMu-sft9hblz5xMSms32dKaoGxjfAOya25xO9TLqWhWZidUzmcRzHLL1l_IbxBePzi_8vx1usGL-JAp5ClL-7fwgizxMeX3Pm7vHVI99us8Hsej7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