<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/110208>110208</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-cl rejects "extern const __declspec(selectany)" variable as having "non-external linkage" when variable definition includes a struct definition
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dunhor
</td>
</tr>
</table>
<pre>
Wow that title is a mouthful. Here's a concrete example:
```c++
extern const __declspec(selectany) struct { int x; } foo = { 42 };
```
clang-cl gives the error:
```
> clang-cl main.cpp
main.cpp(2,25): error: 'selectany' can only be applied to data items with external linkage
2 | extern const __declspec(selectany) struct { int x; } foo = { 42 };
| ^
1 error generated.
```
Of course, if you give the struct its own definition, the code compiles fine:
```c++
struct bar { int x; };
extern const __declspec(selectany) bar foo = { 42 };
```
MSVC compiles both without issue.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VE2PmzoU_TVmcxUE1xCSBYtJMtHbPL3Fk9rlyJgLuDU2sk0y-feVIUqkTqvOppaVyL6f5_hchPeqN0Q1Kw-sPCViDoN1dTubwbqkse2t_mqvEAYRIKigCZQHAaOdw9DNOoV_yBHDKl5Ka6SjQEDvYpw0Mf7CshPLXtg2W7dkeIh7uaX3QM7EKB_g7a0lqf1EkuHOkyYZhLkx3IMPbpYBWHUAZQK8M34AVp2gsxYYPy2GAuMV44ef6q1HqYXpN1JDry7kIQwE5Jx1H_u7H_krPGJGoUwqp2k1PU64Q4ZHLBnuGX955INIxbP7CqQwYI2-QUMgpkkraiFYaEUQoAKNHq4qDLByITRoZb6LntZqAAAR2RH-HlewrFjjd4uVr6trvsKEngw5EahNf0nffx1IOztPDI-gOrjZeWF-If7eoQoe7NVAS50yKihronN0kLaNP-OkNHnolPmTjO4ZG-E-4H6A_CR9McfnZfXv_1-Oz04bG4blLe0cQHk_U5q0NW_3fC8SqvMKqyIvd9U2GWrMspxzwXlWYkn7dktN1wpRdrsci5ZXiaoxwyLbY5WVRcG3aV7wvGi6pti3OafdlhUZjULpVOvLmFrXJ0vJOs8zzHaJFg1pv8w0oqHr2hBDjCPu6hi0aebesyLTygf_TLPMeP1Qv6NvJIMHhvg5DhkiXIRTotEEwsMgLsr0Md5Ys_kgc0S4DmSeIU9BgDJSzy3FL8v9jZ_GZHa6HkKYfFQHnhmeexWGuUmlHRmeI57732ZyNoJgeF5Y8AzPd5ouNf4IAAD__9hPiCw">