llvm / llvm/llvm-project

clang-cl fails to compile dllexported class with std::vector of forward-declared nested type when using /std:c++20 compiler flag

Open
#165,668 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend constexpr diverges-from:msvc extension:microsoft
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Hi,

The following program compiles successfully with the MSVC cl compiler, but fails to compile with clang-cl, even when the /clang:-fms-compatibility flag is specified.

`> clang-cl.exe -c test.cpp /std:c++20 /clang:-fms-compatibility `

```
#include

struct __declspec(dllexport) Foo {
class NestedFoo; // Forward declaration
std::vector v;
};

// Define the NestedFoo
struct __declspec(dllexport) Foo::NestedFoo {
int i ;
};

```
**Error:**
```

C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\vector(683,78): error: arithmetic on a pointer to an incomplete type 'value_type' (aka 'Foo::NestedFoo')
683 | const auto _Count = static_cast(_Right_data._Mylast - _Right_data._Myfirst);
|
```

```
> clang-cl.exe --version
clang version 21.1.1
Target: x86_64-pc-windows-msvc
Thread model: posix
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.