<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125952>125952</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
On Windows, can't create constexpr assignment for function pointer of function marked with dllimport
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cgagnon-mw
</td>
</tr>
</table>
<pre>
I couldn't find this issue reported here, but if it's already been handled, feel free to archive this.
This code compiles on Mac and Linux (using the equivalent import/export annotations), but not on Windows:
```cpp
class __declspec(dllimport) MyClass {
public:
int* foo(int) const;
};
static constexpr auto(MyClass::*bar)(int) const = &MyClass::foo;
```
Here's the error output:
```txt
<source>:6:33: error: constexpr variable 'bar' must be initialized by a constant expression
static constexpr auto(MyClass::*bar)(int) const = &MyClass::foo;
^ ~~~~~~~~~~~~~
```
The program compiles on Windows if you replace `dllimport` with `dllexport`.
It also compiles if you simply remove `constexpr`. Using `constinit` gives essentially the same error.
Here's a similar issue report for MSVC (not authored by me).
https://developercommunity.visualstudio.com/t/cannot-constinitconstexpr-initialize-a/10456333
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VE2P4zYM_TXMhUjgyHEcH3zwzuygC3TQQ7ftcUFLTKxWllx9ZCY99LcXsjOTzfS8QoBIsvhIPj6SQtAny9xC9QmqxxWlODjfyhOdrLPr8WXVO3Vpv6B0ySgLoo541FZhHHRAHUJi9Dw5H1nhwJ5BPGCfIuoj6giiDkjGM6kL9swWB7LKsMqvjswGj54Zo0PyctBnnmE3UHRQdF-zB-kUo3TjpA0HdBafSSJZhT9rm14RxCEFbU8YB0b-O-kzGbYR9ZhDAvHEr3mDZK2LFLWzAUTzFqN1MUP-oa1yLwHK7BX2xfKT0wRFJw2FgN--KZYmTCxBHJQxb_ANPl8e5hdQf4Kiwyn1RssFCfPSNoLo8OgciMN8aFA6GyKU2QDqx2UTcn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