Issue |
145400
|
Summary |
[clang-cl] `constexpr` fields cannot reference DLL exported symbols unlike with MSVC cl
|
Labels |
new issue
|
Assignees |
|
Reporter |
andrurogerz
|
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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs