zequanwu added inline comments.

================
Comment at: clang/lib/Sema/SemaInit.cpp:8710
   }
+  QualType fromType = op->getType();
+  auto *fromDecl = fromType.getTypePtr()->getPointeeCXXRecordDecl();
----------------
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.


================
Comment at: clang/lib/Sema/SemaInit.cpp:8713
+  if (fromDecl && !fromDecl->hasDefinition() && !fromDecl->isInvalidDecl() &&
+      fromDecl->getDeclKind() == Decl::CXXRecord)
+    S.Diag(fromDecl->getLocation(), diag::note_forward_declaration)
----------------
hans wrote:
> Is the getDeclKind() still necessary even though you're doing 
> getPointeeCXXRecordDecl() above and fromDecl is os type CXXRecordDecl*?
Because I was thinking about excluding class template. 
getPointeeCXXRecordDecl() might return a `ClassTemplateSpecializationDecl` or 
`ClassTemplatePartialSpecializationDecl`.
For following example, it triggers the same error. Should the new note also be 
emitted for this case? 
```
template<class C> class A{};
A<int> *a1;
A<char> *a2 = a1;
```
And the following code compiles:
```
template<class C> class A{};
template<> class A<char>{};
template<> class A<int> : public A<char>{};
A<int> *a1;
A<char> *a2 = a1;
```
This seems like the same error as normal class, could resolved by inheritance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85390

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to