Skip to content

Commit 86390b1

Browse files
committed
fixed readability-inconsistent-ifelse-braces clang-tidy warnings
1 parent f210c89 commit 86390b1

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

simplecpp.cpp

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,9 @@ namespace {
459459
// TODO: use ungetc() as well
460460
// UTF-16 has subsequent unget() calls
461461
fseek(file, -1, SEEK_CUR);
462-
} else
462+
} else {
463463
ungetc(ch, file);
464+
}
464465
}
465466

466467
FILE *file;
@@ -1181,8 +1182,9 @@ void simplecpp::TokenList::constFoldMulDivRem(Token *tok)
11811182
continue;
11821183

11831184
long long result;
1184-
if (tok->op == '*')
1185+
if (tok->op == '*') {
11851186
result = (stringToLL(tok->previous->str()) * stringToLL(tok->next->str()));
1187+
}
11861188
else if (tok->op == '/' || tok->op == '%') {
11871189
const long long rhs = stringToLL(tok->next->str());
11881190
if (rhs == 0)
@@ -1194,8 +1196,9 @@ void simplecpp::TokenList::constFoldMulDivRem(Token *tok)
11941196
result = (lhs / rhs);
11951197
else
11961198
result = (lhs % rhs);
1197-
} else
1199+
} else {
11981200
continue;
1201+
}
11991202

12001203
tok = tok->previous;
12011204
tok->setstr(toString(result));
@@ -1419,8 +1422,9 @@ std::string simplecpp::TokenList::readUntil(Stream &stream, const Location &loca
14191422
ret.erase(ret.size()-1U);
14201423
backslash = (next == '\r');
14211424
update_ch = false;
1422-
} else if (next == '\\')
1425+
} else if (next == '\\') {
14231426
update_ch = !update_ch;
1427+
}
14241428
ret += next;
14251429
} while (next == '\\');
14261430
if (update_ch)
@@ -1541,8 +1545,9 @@ namespace simplecpp {
15411545
if (this != &other) {
15421546
files = other.files;
15431547
valueDefinedInCode_ = other.valueDefinedInCode_;
1544-
if (other.tokenListDefine.empty())
1548+
if (other.tokenListDefine.empty()) {
15451549
parseDefine(other.nameTokDef);
1550+
}
15461551
else {
15471552
tokenListDefine = other.tokenListDefine;
15481553
parseDefine(tokenListDefine.cfront());
@@ -1611,15 +1616,17 @@ namespace simplecpp {
16111616
if (par==0)
16121617
break;
16131618
--par;
1614-
} else if (macro2tok->op == ')')
1619+
} else if (macro2tok->op == ')') {
16151620
++par;
1621+
}
16161622
macro2tok = macro2tok->previous;
16171623
}
16181624
if (macro2tok) { // macro2tok->op == '('
16191625
macro2tok = macro2tok->previous;
16201626
expandedmacros.insert(name());
1621-
} else if (rawtok->op == '(')
1627+
} else if (rawtok->op == '(') {
16221628
macro2tok = output2.back();
1629+
}
16231630
if (!macro2tok || !macro2tok->name)
16241631
break;
16251632
if (output2.cfront() != output2.cback() && macro2tok->str() == this->name())
@@ -1639,8 +1646,9 @@ namespace simplecpp {
16391646
const Token *rawtok2 = rawtok;
16401647
for (; rawtok2; rawtok2 = rawtok2->next) {
16411648
rawtokens2.push_back(new Token(rawtok2->str(), loc));
1642-
if (rawtok2->op == '(')
1649+
if (rawtok2->op == '(') {
16431650
++par;
1651+
}
16441652
else if (rawtok2->op == ')') {
16451653
if (par <= 1U)
16461654
break;
@@ -1837,16 +1845,18 @@ namespace simplecpp {
18371845
parametertokens.push_back(nameTokInst->next);
18381846
unsigned int par = 0U;
18391847
for (const Token *tok = nameTokInst->next->next; calledInDefine ? sameline(tok, nameTokInst) : (tok != nullptr); tok = tok->next) {
1840-
if (tok->op == '(')
1848+
if (tok->op == '(') {
18411849
++par;
1850+
}
18421851
else if (tok->op == ')') {
18431852
if (par == 0U) {
18441853
parametertokens.push_back(tok);
18451854
break;
18461855
}
18471856
--par;
1848-
} else if (par == 0U && tok->op == ',' && (!variadic || parametertokens.size() < args.size()))
1857+
} else if (par == 0U && tok->op == ',' && (!variadic || parametertokens.size() < args.size())) {
18491858
parametertokens.push_back(tok);
1859+
}
18501860
}
18511861
return parametertokens;
18521862
}
@@ -1874,8 +1884,9 @@ namespace simplecpp {
18741884
tokens.back()->macro = name();
18751885
}
18761886

1877-
if (tok->op == '(')
1887+
if (tok->op == '(') {
18781888
++par;
1889+
}
18791890
else if (tok->op == ')') {
18801891
--par;
18811892
if (par == 0U)
@@ -1948,8 +1959,9 @@ namespace simplecpp {
19481959

19491960
const MacroMap::const_iterator m = macros.find("__COUNTER__");
19501961

1951-
if (!counter || m == macros.end())
1962+
if (!counter || m == macros.end()) {
19521963
parametertokens2.swap(parametertokens1);
1964+
}
19531965
else {
19541966
const Macro &counterMacro = m->second;
19551967
unsigned int par = 0;
@@ -2138,8 +2150,9 @@ namespace simplecpp {
21382150
TokenList tokens(files);
21392151
tokens.push_back(new Token(*tok));
21402152
const Token * tok2 = nullptr;
2141-
if (tok->next->op == '(')
2153+
if (tok->next->op == '(') {
21422154
tok2 = appendTokens(tokens, loc, tok->next, macros, expandedmacros, parametertokens);
2155+
}
21432156
else if (expandArg(tokens, tok->next, loc, macros, expandedmacros, parametertokens)) {
21442157
tokens.front()->location = loc;
21452158
if (tokens.cfront()->next && tokens.cfront()->next->op == '(')
@@ -2315,12 +2328,15 @@ namespace simplecpp {
23152328
const bool varargs = variadic && !args.empty() && B->str() == args[args.size()-1U];
23162329

23172330
if (expandArg(tokensB, B, parametertokens)) {
2318-
if (tokensB.empty())
2331+
if (tokensB.empty()) {
23192332
strAB = A->str();
2320-
else if (varargs && A->op == ',')
2333+
}
2334+
else if (varargs && A->op == ',') {
23212335
strAB = ",";
2322-
else if (varargs && unexpectedA)
2336+
}
2337+
else if (varargs && unexpectedA) {
23232338
throw invalidHashHash::unexpectedToken(tok->location, name(), A);
2339+
}
23242340
else {
23252341
strAB = A->str() + tokensB.cfront()->str();
23262342
tokensB.deleteToken(tokensB.front());
@@ -2339,8 +2355,9 @@ namespace simplecpp {
23392355
throw invalidHashHash::universalCharacterUB(tok->location, name(), A, strAB);
23402356
}
23412357

2342-
if (varargs && tokensB.empty() && tok->previous->str() == ",")
2358+
if (varargs && tokensB.empty() && tok->previous->str() == ",") {
23432359
output.deleteToken(A);
2360+
}
23442361
else if (strAB != "," && macros.find(strAB) == macros.end()) {
23452362
A->setstr(strAB);
23462363
for (Token *b = tokensB.front(); b; b = b->next)
@@ -2758,8 +2775,9 @@ long long simplecpp::characterLiteralToLL(const std::string& str)
27582775
pos = 3;
27592776
} else if (str.size() >= 2 && (str[0] == 'L' || str[0] == 'U') && str[1] == '\'') {
27602777
pos = 2;
2761-
} else
2778+
} else {
27622779
throw std::runtime_error("expected a character literal");
2780+
}
27632781

27642782
unsigned long long multivalue = 0;
27652783

@@ -3593,8 +3611,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
35933611
}
35943612

35953613
bool conditionIsTrue;
3596-
if (ifstates.top() == AlwaysFalse || (ifstates.top() == ElseIsTrue && rawtok->str() != ELIF))
3614+
if (ifstates.top() == AlwaysFalse || (ifstates.top() == ElseIsTrue && rawtok->str() != ELIF)) {
35973615
conditionIsTrue = false;
3616+
}
35983617
else if (rawtok->str() == IFDEF) {
35993618
conditionIsTrue = (macros.find(rawtok->next->str()) != macros.end() || (hasInclude && rawtok->next->str() == HAS_INCLUDE));
36003619
maybeUsedMacros[rawtok->next->str()].push_back(rawtok->next->location);

test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ static void assertThrowFailed(int line)
6767

6868
static void testcase(const std::string &name, void (*f)(), int argc, char * const *argv)
6969
{
70-
if (argc == 1)
70+
if (argc == 1) {
7171
f();
72+
}
7273
else {
7374
for (int i = 1; i < argc; i++) {
7475
if (name == argv[i])

0 commit comments

Comments
 (0)