@@ -1055,7 +1055,10 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
10551055 return nullptr ;
10561056 }
10571057 if (nodeType == EnumConstantDecl) {
1058- Token *nameToken = addtoken (tokenList, getSpelling ());
1058+ const std::string name = getSpelling ();
1059+ if (name.empty ())
1060+ throw InternalError (nullptr , " invalid AST node: " + nodeType, InternalError::AST );
1061+ Token *nameToken = addtoken (tokenList, name);
10591062 auto *scope = const_cast <Scope *>(nameToken->scope ());
10601063 scope->enumeratorList .emplace_back (nameToken->scope ());
10611064 Enumerator *e = &scope->enumeratorList .back ();
@@ -1386,6 +1389,10 @@ Token * clangimport::AstNode::createTokensCall(TokenList &tokenList)
13861389
13871390void clangimport::AstNode::createTokensFunctionDecl (TokenList &tokenList)
13881391{
1392+ // an address-only node has no name: addtoken("") adds nothing and would return a null back()
1393+ const std::string name = getSpelling ();
1394+ if (name.empty ())
1395+ throw InternalError (nullptr , " invalid AST node: " + nodeType, InternalError::AST );
13891396 const bool prev = contains (mExtTokens , " prev" );
13901397 const bool hasBody = !children.empty () && children.back ()->nodeType == CompoundStmt;
13911398 const bool isStatic = contains (mExtTokens , " static" );
@@ -1407,7 +1414,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList &tokenList)
14071414 if (mExtTokens .size () > 4 && mExtTokens [1 ] == " parent" )
14081415 addFullScopeNameTokens (tokenList, mData ->getScope (mExtTokens [2 ]));
14091416
1410- Token *nameToken = addtoken (tokenList, getSpelling () + getTemplateParameters ());
1417+ Token *nameToken = addtoken (tokenList, name + getTemplateParameters ());
14111418 auto *nestedIn = const_cast <Scope *>(nameToken->scope ());
14121419
14131420 if (prev) {
0 commit comments