<div dir="ltr"><div>Hi,</div><div><br></div><div>In writing tests for a clang tool, I couldn't find a way to compare a QualType parsed from the AST with a programmatically defined (not parsed from the AST) QualType. In particular, I find it hard to create a QualType from scratch, since although QualType has a default constructor, Type subclasses don't have public constructors. This added flexibility will greatly reduce boilerplate code for my tests. How is this usually done?<br></div><div><br></div><div><div><b>Some context:</b><br></div><div><br></div><div>I'm currently writing some tests for a clang-cast tool that converts C-style casts to C++ style casts. I wanted to test a specific scenario where a reinterpret_cast should be followed by a const_cast, and we havey an intermediate type which doesn't have the necessary qualifiers. For example:</div><div><br></div><div>void f() {<br></div><div>    const int * const ptr;</div><div>    (double*) ptr;</div><div>    const_cast<double*>(reinterpret_cast<const double*>(ptr));</div><div>}<br></div><div><br></div><div>where the intermediate type above is const double* (it could also be const double* const, depending on where you want the implicit <a href="https://timsong-cpp.github.io/cppwp/n4140/conv#lval">lvalue-to-rvalue</a> conversion to happen). In any case, given the subexpression type (ptr), and the cast type (double*) as QualTypes, I wanted to say something along the lines of:</div><div><br></div><div>ASSERT_TRUE(ChangeQualifiers(CastType, SubExpressionType), QualType("const double*"));</div><div><br></div><div>Obviously, this doesn't exactly work because there is no such constructor for QualType. I can append a VarDecl statement into the above code to match a QualType:</div><div><br></div><div>    ...<br></div><div>    const double* ptr; // match the type here</div><div>}<br></div><div><br></div><div>I just want to make sure there's no better way to do this.<br></div><div><br></div><div><div>Best,</div><div>Ray</div></div></div></div>