How can I check if the qualifiers of a type has a class in it?

I get the qualifiers like this:
Qualifiers q = qualifiedType.getQualifiers();

How can I check whether if the qualifiers include a class name ?

I can not figure out how to find this information from the Qualifiers interface.

Types in namespaces …single or nested… should not trigger this check.


Manasij Mukherjee

What do you mean by 'if the qualifiers include a class name"?

Qualifiers class deals with const, volatile, etc.

It seems I made a mistake in terminology.

What is the following called?

Suppose I have the types:



The second type has MyNamespace::ClassName as its scope (?).

I want to detect if there are only namespaces there or a class somewhere in the scope .

It looks like you’re looking for NestedNameSpecifier. You should check the Kind and traverse the Prefix. I don’t know how you obtain the type as it can appear in various contexts, but assuming you have some kind of Decl object on your hands you can call the the getQualifier() method.

I have a FunctionDecl while overriding VisitFunctionDecl of ASTVisitor.

I did Decl->getQualifier()->getKind() == NestedNameSpecifier::TypeSpec

But it segfaults in getKind

So, I am probably calling getQualifier from the wrong thing.

Decl->getQualifier() is always returning a null value.

When is a valid qualifier returned?

My input code is:
namespace test { //nested name specifier
class HasSubType {
class SubType {};
HasSubType::SubType FunctionUsingSubtype(HasSubType::SubType s){return s;}
extern HasSubType::SubType variable;
HasSubType FunctionNotUsingSubType(HasSubType h){return h;}

I want to filter out FunctionUsingSubType and the variable.


That’s because the function itself doesn’t have a qualifier. You should be looking at return type and parameter types in case of FunctionDecl. I can’t tell you how to do this exactly but there should be a way to do it. Also take a look at CXXScopeSpecifier, if you can get this from the type NestedNameSpecifier can be obtained from it.