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

    <tr>
        <th>Summary</th>
        <td>
            [clang-cl] `constexpr` fields cannot reference DLL exported symbols unlike with MSVC cl
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    This is a minor behavioral difference between `clang`/`clang-cl` and MSVC `cl` when dealing with DLL exported symbols.: when compiling with MSVC, a `constexpr` variable is allowed to reference a symbol that is DLL-exported. When compiling the same code with `clang-cl`, an error is produced indicating the variable must be initialized by a constant expression.

Simplest repro:
DLL source:
```
__declspec(dllexport) int sum(int a, int b) {
  return a + b;
}
```

Client source:
```
__declspec(dllimport) void sum();
constexpr auto sumFn = sum;
```

Compiling this code with `clang-cl` results in:
```
error: constexpr variable 'sumFn' must be initialized by a constant expression
 167 |     constexpr auto sumFn = sum;
      |                    ^ ~~~
1 error generated.
```

Honestly, it seems like Clang is correct to disallow this and MSVC is in the wrong. However, if `clang-cl` is meant to be a drop-in replacement for `cl` on Windows then it would need to behave the same.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVE1v4zYQ_TX0ZRCDoiwrOujg2DX2kJ626B4XFDm2pqVIgaSszR7y2wtStrObtGhLGDA_Rm_evPmQIdDZIrasemLVYSWn2DvfSqv95N0Z_fdV5_RL-1tPASiAhIGs89BhLy_kvDSg6XRCj1YhdBhnRAtsy5WR9sy2nInj7fSgDNtykFbDr59_3y9W6Wbu0YJGacieYabYw-H5GfDb6HxEDeFl6JwJa1buFlPlhpHejBMYE3uQGdHZEPHb6BPwRXqSncHM3Bg3o4bowOONsLyCQ-xlTFaH5-eHm-M1fPnZW-wRghwQlNO4-P45tszCAnrvfEIbvdOTQg1kNSkZbyB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