<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99825>99825</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unexpected internal linkage of const/constexpr variable within extern "C++"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kamrann
</td>
</tr>
</table>
<pre>
clang rejects the following with `error: declaration of 'x' with internal linkage cannot be exported`:
```
export module mod;
extern "C++"
{
export constexpr auto x = 10;
}
```
Compiler explorer: https://godbolt.org/z/a6nhazoKr
According to [[basic.link] 3.2](https://eel.is/c++draft/basic.link#3.2), `const` (or `constexpr` ) implies internal linkage for a namespace scope variable, with some exceptions, and 3.2.1 states that one such exception is if the declaration is in the purview of a module interface. clang appears to respect this generally, but in the case of `extern "C++"` it seems to not apply this exception, as if it considers the contents of such a block to not be part of the module's purview. This feels like a corner case, since obviously the symbols are not attached to the module; but the purview is nonetheless defined as all tokens following the module declaration and I can't see anywhere that states a linkage block is exempt.
Note that MSVC accepts the code.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVF2PqzgM_TXpi3URDVDKAw8zU1VarXZf9uPdJKZkJyQoCfNxf_3KoZ3pvXckJNrgHB8fHxtjNBdH1IvmUTSnHa5p8qF_xjmgc7vB6_deWXQXCPQfqRQhTQSjt9a_GneBV5MmEIeSQvBBVA-gSVkMmIx34EcQsn0Tst3ijEsUHFqwxj3jhUChcz7BQEBviw-JtDiUonoQ5UmUD_x7e_LfLQRmr1dL_BLV4zXw-p3RQUj5JORjfuT1e3sNvKYB5V1M9LYEwDV5eANRnWBffgK2p3vkn4g8-XkxlgKjWR8o1z2ltESmLs9Cni9eD96mwoeLkOfvQp7x4Cb87n8P98APSvmgWcfkIXfgccBoVMECieYEVSFFcxLy-CM8kS1MFPKstkp1wDEJeb67LCu-Kzshn7g_uWJxKEHIow8f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