@@ -874,7 +874,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
874
874
back ()->setstr (currentToken);
875
875
location.adjust (currentToken);
876
876
if (currentToken.find_first_of (" \r\n " ) == std::string::npos)
877
- location.col += 2 + 2 * delim.size ();
877
+ location.col += 2 + ( 2 * delim.size () );
878
878
else
879
879
location.col += 1 + delim.size ();
880
880
@@ -1329,6 +1329,7 @@ void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
1329
1329
void simplecpp::TokenList::constFoldQuestionOp (Token **tok1)
1330
1330
{
1331
1331
bool gotoTok1 = false ;
1332
+ // NOLINTNEXTLINE(misc-const-correctness) - technically correct but used to access non-const data
1332
1333
for (Token *tok = *tok1; tok && tok->op != ' )' ; tok = gotoTok1 ? *tok1 : tok->next ) {
1333
1334
gotoTok1 = false ;
1334
1335
if (tok->str () != " ?" )
@@ -1508,7 +1509,12 @@ namespace simplecpp {
1508
1509
}
1509
1510
1510
1511
Macro (const Macro &other) : nameTokDef(nullptr ), files(other.files), tokenListDefine(other.files), valueDefinedInCode_(other.valueDefinedInCode_) {
1511
- *this = other;
1512
+ // TODO: remove the try-catch - see #537
1513
+ // avoid bugprone-exception-escape clang-tidy warning
1514
+ try {
1515
+ *this = other;
1516
+ }
1517
+ catch (const Error&) {} // NOLINT(bugprone-empty-catch)
1512
1518
}
1513
1519
1514
1520
~Macro () {
@@ -1945,6 +1951,7 @@ namespace simplecpp {
1945
1951
}
1946
1952
}
1947
1953
1954
+ // NOLINTNEXTLINE(misc-const-correctness) - technically correct but used to access non-const data
1948
1955
Token * const output_end_1 = output.back ();
1949
1956
1950
1957
const Token *valueToken2;
@@ -2250,7 +2257,7 @@ namespace simplecpp {
2250
2257
const bool canBeConcatenatedStringOrChar = isStringLiteral_ (A->str ()) || isCharLiteral_ (A->str ());
2251
2258
const bool unexpectedA = (!A->name && !A->number && !A->str ().empty () && !canBeConcatenatedWithEqual && !canBeConcatenatedStringOrChar);
2252
2259
2253
- Token * const B = tok->next ->next ;
2260
+ const Token * const B = tok->next ->next ;
2254
2261
if (!B->name && !B->number && B->op && !B->isOneOf (" #=" ))
2255
2262
throw invalidHashHash::unexpectedToken (tok->location , name (), B);
2256
2263
@@ -2528,11 +2535,11 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
2528
2535
for (simplecpp::Token *tok = expr.front (); tok; tok = tok->next ) {
2529
2536
if (tok->str () != " sizeof" )
2530
2537
continue ;
2531
- simplecpp::Token *tok1 = tok->next ;
2538
+ const simplecpp::Token *tok1 = tok->next ;
2532
2539
if (!tok1) {
2533
2540
throw std::runtime_error (" missing sizeof argument" );
2534
2541
}
2535
- simplecpp::Token *tok2 = tok1->next ;
2542
+ const simplecpp::Token *tok2 = tok1->next ;
2536
2543
if (!tok2) {
2537
2544
throw std::runtime_error (" missing sizeof argument" );
2538
2545
}
@@ -2547,7 +2554,7 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
2547
2554
}
2548
2555
2549
2556
std::string type;
2550
- for (simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next ) {
2557
+ for (const simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next ) {
2551
2558
if ((typeToken->str () == " unsigned" || typeToken->str () == " signed" ) && typeToken->next ->name )
2552
2559
continue ;
2553
2560
if (typeToken->str () == " *" && type.find (' *' ) != std::string::npos)
@@ -2598,11 +2605,11 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
2598
2605
for (simplecpp::Token *tok = expr.front (); tok; tok = tok->next ) {
2599
2606
if (tok->str () != HAS_INCLUDE)
2600
2607
continue ;
2601
- simplecpp::Token *tok1 = tok->next ;
2608
+ const simplecpp::Token *tok1 = tok->next ;
2602
2609
if (!tok1) {
2603
2610
throw std::runtime_error (" missing __has_include argument" );
2604
2611
}
2605
- simplecpp::Token *tok2 = tok1->next ;
2612
+ const simplecpp::Token *tok2 = tok1->next ;
2606
2613
if (!tok2) {
2607
2614
throw std::runtime_error (" missing __has_include argument" );
2608
2615
}
@@ -2620,7 +2627,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
2620
2627
const bool systemheader = (tok1 && tok1->op == ' <' );
2621
2628
std::string header;
2622
2629
if (systemheader) {
2623
- simplecpp::Token *tok3 = tok1->next ;
2630
+ const simplecpp::Token *tok3 = tok1->next ;
2624
2631
if (!tok3) {
2625
2632
throw std::runtime_error (" missing __has_include closing angular bracket" );
2626
2633
}
@@ -2631,7 +2638,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
2631
2638
}
2632
2639
}
2633
2640
2634
- for (simplecpp::Token *headerToken = tok1->next ; headerToken != tok3; headerToken = headerToken->next )
2641
+ for (const simplecpp::Token *headerToken = tok1->next ; headerToken != tok3; headerToken = headerToken->next )
2635
2642
header += headerToken->str ();
2636
2643
} else {
2637
2644
header = tok1->str ().substr (1U , tok1->str ().size () - 2U );
0 commit comments