Open
Description
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:
class __declspec(dllimport) MyClass {
public:
int* foo(int) const;
};
static constexpr auto(MyClass::*bar)(int) const = &MyClass::foo;
Here's the error output:
<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