abseil / abseil/abseil-cpp

MSVC2019 complains about reinterpret_cast in absl::Condition

オープン
#971 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
C++
スター
18.1k
フォーク
3.2k
平均マージ
20時間 36分
マージ済み PR(30日)
1

説明

**Describe the bug**

MSVC2019 fails to compile the following code snippet:

```cpp
#include "absl/synchronization/mutex.h"
#include

struct A : std::enable_shared_from_this {
virtual ~A() = default;
};

struct B : A {
bool is_ready();

void func() {
absl::Condition{this, &B::is_ready};
}
};
```

The root cause seems to be a `reinterpret_cast` which casts between member function pointers of different classes.
Those have the same size in GCC/Clang but apparently they are different in MSVC.

Error message:
```

C:/data/libraries/installed/x64-windows/include\absl/synchronization/mutex.h(946): error C2440: 'reinterpret_cast': cannot convert from 'bool (__cdecl B::* )(void)' to 'absl::Condition::InternalMethodType'
C:/data/libraries/installed/x64-windows/include\absl/synchronization/mutex.h(946): note: Pointers to members have different representations; cannot cast between them
(12): note: see reference to function template instantiation 'absl::Condition::Condition(T *,bool (__cdecl B::* )(void))' being compiled
with
[
T=B
]
Compiler returned: 2
```

**Steps to reproduce the bug**

A minimal breaking example is here: https://gcc.godbolt.org/z/ff5qczj4M

**What version of Abseil are you using?**

trunk and latest LTS. Both are affected.

**What operating system and version are you using**

Windows 10

**What compiler and version are you using?**

So far I've only tried MSVC2019. I assume that all versions of MSVC which share the same ABI (2015,2017,2019) are affected.

**What build system are you using?**

CMake 3.18.4 - but I guess that's not so relevant.

**Additional context**

I'm no expert in C++ standardese, but I seems to me that MSVC is correct in the sense that it is allowed to have member function pointers with different underlying data structures which can't be casted to each other.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。