NoQ added inline comments.

================
Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:126
+
+  // If the casts have a common anchestor it could not be a succeeded downcast.
+  for (const auto &PreviousBase : PreviousRD->bases())
----------------
Charusso wrote:
> NoQ wrote:
> > Counterexample:
> > 
> > ```
> > struct A {};
> > struct B : A {};
> > struct C : A, B {};
> > ```
> > 
> > Downcast from `C` to `B` should succeed, even though they have a common 
> > ancestor `A` (which has the same `CXXRecordDecl` but currently isn't the 
> > same object within `C`, but can be, if `B` declares `A` as a virtual base).
> So, even it is some kind of anti-pattern as a warning arrive immediately, now 
> I allow `B` to `C` downcasts. Could you explain me more about that virtual 
> idea, please? Based on this possible use-case in my mind two classes are on 
> the same level as every of their bases/vbases are equals.
> Could you explain me more about that virtual idea, please?

In the following variation:
```
struct A {};
struct B : virtual A {};
struct C : A, B {};
```
we have `C` contain only one instance of `A`: the layout of `B` within `C` 
would merely refer to the instance of `A` within `C` instead of making its own 
copy. In particular, the constructor of `B` within the constructor of `C` would 
not initialize `C`'s instance of `A` because the constructor of `C` will invoke 
the constructor of `A` directly (cf. D61816).


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

https://reviews.llvm.org/D67079



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

Reply via email to