Open
Description
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.
There is some further discussion in #144386