@@ -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 ();
@@ -1391,6 +1394,10 @@ Token * clangimport::AstNode::createTokensCall(TokenList &tokenList)
13911394
13921395void clangimport::AstNode::createTokensFunctionDecl (TokenList &tokenList)
13931396{
1397+ // an address-only node has no name: addtoken("") adds nothing and would return a null back()
1398+ const std::string name = getSpelling ();
1399+ if (name.empty ())
1400+ throw InternalError (nullptr , " invalid AST node: " + nodeType, InternalError::AST );
13941401 const bool prev = contains (mExtTokens , " prev" );
13951402 const bool hasBody = !children.empty () && children.back ()->nodeType == CompoundStmt;
13961403 const bool isStatic = contains (mExtTokens , " static" );
@@ -1412,7 +1419,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList &tokenList)
14121419 if (mExtTokens .size () > 4 && mExtTokens [1 ] == " parent" )
14131420 addFullScopeNameTokens (tokenList, mData ->getScope (mExtTokens [2 ]));
14141421
1415- Token *nameToken = addtoken (tokenList, getSpelling () + getTemplateParameters ());
1422+ Token *nameToken = addtoken (tokenList, name + getTemplateParameters ());
14161423 auto *nestedIn = const_cast <Scope *>(nameToken->scope ());
14171424
14181425 if (prev) {
0 commit comments