On Wed, Feb 3, 2016 at 3:52 PM, Hubert Tong < hubert.reinterpretc...@gmail.com> wrote:
> hubert.reinterpretcast added inline comments. > > ================ > Comment at: lib/Sema/SemaExpr.cpp:1156-1159 > @@ +1155,6 @@ > + > + QualType LHSElemType = dyn_cast<ComplexType>(LHSType) ? > + cast<ComplexType>(LHSType)->getElementType() : LHSType; > + QualType RHSElemType = dyn_cast<ComplexType>(RHSType) ? > + cast<ComplexType>(RHSType)->getElementType() : RHSType; > + > ---------------- > rsmith wrote: > > hubert.reinterpretcast wrote: > > > The result of the `dyn_cast` can be saved instead of using `cast` > after the `dyn_cast`. > > Do not use `dyn_cast` / `cast` on types, use `LHSType->getAs<...>()` / > `LHSType->castAs<...>()` instead. This will do the wrong thing on sugared > types (eg, a typedef for a complex type). > Are there contexts in Clang where sugared types don't occur? Is the > general guidance to use `getAs` or `castAs` even if the types are known to > be canonical (which I agree isn't the case here)? If you're intentionally inspecting the immediate type sugar node, then dyn_cast/cast are appropriate. If it's obvious from context that you have a canonical type, then they're OK (and might be marginally faster), but it's an immediate red flag to a reader of the code to see those operations, so they should often be avoided for that reason even if they're correct.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits