How to get the AST of an expression serving as a template argument?

For example, in the program below RecursiveASTVisitor sees the template
argument as the integer 6. How to get the actual expression "n+n"?

template<int m>
struct S {
};

const int n = 3;

template<>
struct S<n+n> {
};

int main() {
    S<6> s;
}

Sorry I can’t give you the exact code but you want to get the primary template this was instantiated from (I think getTemplatedDecl returns it) and look at its argument.

Thanks! I found that you can get it from TemplateSpecializationDecl,
code is below.

    if (TypeSourceInfo* tsi = specDecl->getTypeAsWritten()) {
        if (auto typeLoc =
tsi->getTypeLoc().getAs<TemplateSpecializationTypeLoc>()) {
            for (unsigned i = 0; i < typeLoc.getNumArgs(); ++i) {
                TemplateArgumentLocInfo locInfo = typeLoc.getArgLocInfo(i);
                Expr* expr = locInfo.getAsExpr();
                //expr->dump();
            }
        }
    }