From 30426ac58f68502197a758ad132ac67b1d352974 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 7 Aug 2023 18:28:30 +0800 Subject: [PATCH] Crash when enum value is a symbol that not valid. --- RedPandaIDE/parser/cppparser.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 03fba771..5d7361b4 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1847,12 +1847,14 @@ int CppParser::evaluateConstExprTerm(int endIndex, bool &ok) || mTokenizer[mIndex]->text=="::") { QString s = mTokenizer[mIndex]->text; QSet searched; + bool isGlobal = false; mIndex++; if (s=="::") { if (mIndex>=endIndex || !isIdentChar(mTokenizer[mIndex]->text[0])) { ok=false; return result; } + isGlobal = true; s+=mTokenizer[mIndex]->text; mIndex++; } @@ -1869,7 +1871,10 @@ int CppParser::evaluateConstExprTerm(int endIndex, bool &ok) return result; } searched.insert(s); - PStatement statement = doFindStatement(s); + PStatement statement = doFindStatementOf( + mCurrentFile,s, + isGlobal?PStatement():getCurrentScope()); + if (!statement) { ok=false; return result; @@ -1877,6 +1882,11 @@ int CppParser::evaluateConstExprTerm(int endIndex, bool &ok) if (statement->kind == StatementKind::skEnum) { result = statement->value.toInt(&ok); break; + } else if (statement->kind == StatementKind::skAlias) { + s = statement->value; + } else { + ok=false; + return result; } } } else {