Get underlying type of QualType if it's TypedefType

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Get underlying type of QualType if it's TypedefType

Daniel Marjamäki via cfe-dev
Hi All,

  I have SrcType and DestType used in explicit cast, and I'd like to check if the type conversion is valid in CastOperation::CheckCStyleCast [1]. The code snippet below (just get the idea, the code is not runable),

    Builtin *Src   = dyn_cast<BuiltinType>(SrcExpr.get()->getType());
    Builtin *Dest = dyn_cast<BuiltinType>(DestType);

    if (Src.getKind() == Dest.getKind()) {
      // do something
    } else {
      // do something else

The problem is the SrcType and DestType might be typedef. For example,

    typedef foo FOO;

    FOO b = (FOO)(a);

Src and Dest might be nullptr due to the fail dyn_cast, and I will get segfault while calling getKind() upon them.
I am not familiar with Clang, so is there a better way that I can get the underlying type if SrcType and DestType
are typedef?



Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj

cfe-dev mailing list
[hidden email]