Help getting source locations for type qualifiers

Hi all,

Consider the following declaration:

const char *const ptr = 0;

With an ordinary TypeLoc, I can get the SourceRange corresponding to the “char *” part of the type by calling getSourceRange(), but I would like to get the SourceRange of the whole qualtype, i.e. “const char *const”. The documentation seems to suggest that this should be possible via the TypeLoc::findExplicitQualifierLoc() function, which “Find[s] a type with the location of an explicit type qualifier.” The implementation casts the TypeLoc to a QualifiedTypeLoc and returns the result. However, the documentation for QualifiedTypeLoc states that “Currently, we intentionally do not provide source location for type qualifiers.”

Does this mean that what I want to do is not possible?

Thanks in advance,

Scott Constable


You can try getting previous token and checking whether it’s a part of the qualtype (and if so, extending SourceRange). I don’t know how to do this in a clean way (tm), but at least it should work.