[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

Deep Majumder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 1 03:28:09 PST 2021


RedDocMD marked an inline comment as done.
RedDocMD added inline comments.


================
Comment at: clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp:43-50
+struct A {};
+struct B : public A {};
+struct C {
+  int field;
+};
+struct D : public C {};
+struct E : public B, public D {};
----------------
steakhal wrote:
> An ASCII art would help so much:
> ```
> A   C(field)
> |   |
> B   D
>  \ /
>   E
>   |
>   F
> ```
> However, I'm still missing a diamond-shaped inheritance.
> An ASCII art would help so much:
> ```
> A   C(field)
> |   |
> B   D
>  \ /
>   E
>   |
>   F
> ```
> However, I'm still missing a diamond-shaped inheritance.

Thanks for the ASCII art!
The diamond-shaped inheritance as far as I understood will cause illegal code.
Eg:
```
       A
       |
       B
     /   \
    C     D
     \   /
       E
```
According to my understanding, if I have a field in A or B, and try to define a member pointer like `int E::* ef = &A::field`, it is not allowed.
On GCC, this is the error message I get:
```
struct A {
  int field;
};

struct B : public A {};
struct C : public virtual B {};
struct D : public virtual B {};
struct E : public C, public D {};

int main() {
  int E::* ef1 = &A::field;
}
```
diamond-member-pointer.cpp: In function ‘int main()’:
diamond-member-pointer.cpp:11:22: error: pointer to member conversion via virtual base ‘B’
   11 |   int E::* ef1 = &A::field;
      |                      ^~~~~
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96976/new/

https://reviews.llvm.org/D96976



More information about the cfe-commits mailing list