Attempting to get type from typedef struct causes crash

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

Attempting to get type from typedef struct causes crash

Alexandre Ganea via cfe-dev



I am trying to write a custom clang-tidy check (I want to check for the use of CAdapt<>) but have been struggling with the following issue: I am trying to make an AST matcher which checks the string representation of the type of a VarDecl - but when it runs on certain code it crashes and I can’t figure out why. The issue seems to be some interaction between QualType::getAsString() and typedef struct variables, (there may be other code which crashes it but this is what I have been able to find). The issue can be reproduced with the following custom clang-tidy check (apologies if there is a more sensible way to make a minimal repro than a clang-tidy check):



#include "CrashingCheck.h"

#include "clang/AST/ASTContext.h"

#include "clang/ASTMatchers/ASTMatchFinder.h"


using namespace clang::ast_matchers;


namespace clang {

namespace tidy {

namespace misc {


    namespace {

        AST_MATCHER(VarDecl, isMatch) {


            return false;




    void CrashingCheck::registerMatchers(MatchFinder *Finder) {

        Finder->addMatcher(varDecl(isMatch()).bind("varDecl"), this);



    void CrashingCheck::check(const MatchFinder::MatchResult &Result) {}




Which crashes when run on:



typedef struct foo{} foo;


int main(){

    foo f;

    return 0;




Is there some restriction on when it is OK to use getAsString() that I am not understanding? Also, if there is a better way to write something like this then do let me know, I’m pretty new to this.




cfe-dev mailing list
[hidden email]