[PATCH] D85390: [Clang] Add note for bad conversion error when expression is of forward-declared type

Zequan Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 6 14:28:08 PDT 2020


zequanwu added inline comments.


================
Comment at: clang/lib/Sema/SemaInit.cpp:8710
   }
+  QualType fromType = op->getType();
+  auto *fromDecl = fromType.getTypePtr()->getPointeeCXXRecordDecl();
----------------
zequanwu wrote:
> hans wrote:
> > Can the reverse situation happen, where it's destType that's forward declared?
> If we only consider normal class without template, I think it's not necessary.
> Here is an example of forward-declared destType.
> ```
> class B{};
> class A;
> B *b;
> A *a= b;
> ```
> Even if A is defined as `class A: public B{};`, `A *a = b` is still not valid, initializing pointer to derived class with pointer to base class.
The reverse situation could happen in class template.
```
template<class C> class A{};
template<class C> class B; // template<class C> class B : public A<C>{}; compiles
B<int> *b;
A<int> *a = b;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85390



More information about the cfe-commits mailing list