Skip to content

Commit b75ddaf

Browse files
committed
fix
1 parent 47ead4b commit b75ddaf

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

simplecpp.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ static const simplecpp::TokenString IFNDEF("ifndef");
9696
static const simplecpp::TokenString DEFINED("defined");
9797
static const simplecpp::TokenString ELSE("else");
9898
static const simplecpp::TokenString ELIF("elif");
99+
static const simplecpp::TokenString ELIFDEF("elifdef");
100+
static const simplecpp::TokenString ELIFNDEF("elifndef");
99101
static const simplecpp::TokenString ENDIF("endif");
100102

101103
static const simplecpp::TokenString PRAGMA("pragma");
@@ -3580,7 +3582,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35803582
continue;
35813583
}
35823584

3583-
if (ifstates.size() <= 1U && (rawtok->str() == ELIF || rawtok->str() == ELSE || rawtok->str() == ENDIF)) {
3585+
if (ifstates.size() <= 1U && (rawtok->str() == ELIF || rawtok->str() == ELIFDEF ||
3586+
rawtok->str() == ELIFNDEF || rawtok->str() == ELSE ||
3587+
rawtok->str() == ENDIF)) {
35843588
if (outputList) {
35853589
simplecpp::Output err{
35863590
Output::SYNTAX_ERROR,
@@ -3721,7 +3725,8 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37213725
rawtok = filedata->tokens.cfront();
37223726
continue;
37233727
}
3724-
} else if (rawtok->str() == IF || rawtok->str() == IFDEF || rawtok->str() == IFNDEF || rawtok->str() == ELIF) {
3728+
} else if (rawtok->str() == IF || rawtok->str() == IFDEF || rawtok->str() == IFNDEF || rawtok->str() == ELIF ||
3729+
(getCStd(dui.std) >= C23 || getCppStd(dui.std) >= CPP23) && (rawtok->str() == ELIFDEF || rawtok->str() == ELIFNDEF)) {
37253730
if (!sameline(rawtok,rawtok->next)) {
37263731
if (outputList) {
37273732
simplecpp::Output out{
@@ -3736,10 +3741,11 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37363741
}
37373742

37383743
bool conditionIsTrue;
3739-
if (ifstates.top() == AlwaysFalse || (ifstates.top() == ElseIsTrue && rawtok->str() != ELIF)) {
3744+
if (ifstates.top() == AlwaysFalse || (ifstates.top() == ElseIsTrue && rawtok->str() != ELIF &&
3745+
rawtok->str() != ELIFDEF && rawtok->str() != ELIFNDEF)) {
37403746
conditionIsTrue = false;
37413747
}
3742-
else if (rawtok->str() == IFDEF) {
3748+
else if (rawtok->str() == IFDEF || rawtok->str() == ELIFDEF) {
37433749
const std::string &name = rawtok->next->str();
37443750
conditionIsTrue = (macros.find(name) != macros.end() || (hasInclude && name == HAS_INCLUDE));
37453751
maybeUsedMacros[name].emplace_back(rawtok->next->location);
@@ -3748,7 +3754,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37483754
const long long result = conditionIsTrue ? 1 : 0;
37493755
ifCond->emplace_back(rawtok->location, E, result);
37503756
}
3751-
} else if (rawtok->str() == IFNDEF) {
3757+
} else if (rawtok->str() == IFNDEF || rawtok->str() == ELIFNDEF) {
37523758
const std::string &name = rawtok->next->str();
37533759
conditionIsTrue = (macros.find(name) == macros.end() && !(hasInclude && name == HAS_INCLUDE));
37543760
maybeUsedMacros[name].emplace_back(rawtok->next->location);
@@ -3879,7 +3885,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
38793885
}
38803886
}
38813887

3882-
if (rawtok->str() != ELIF) {
3888+
if (rawtok->str() != ELIF && rawtok->str() != ELIFDEF && rawtok->str() != ELIFNDEF) {
38833889
// push a new ifstate..
38843890
if (ifstates.top() != True)
38853891
ifstates.push(AlwaysFalse);

0 commit comments

Comments
 (0)