@@ -874,7 +874,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
874874 back ()->setstr (currentToken);
875875 location.adjust (currentToken);
876876 if (currentToken.find_first_of (" \r\n " ) == std::string::npos)
877- location.col += 2 + 2 * delim.size ();
877+ location.col += 2 + ( 2 * delim.size () );
878878 else
879879 location.col += 1 + delim.size ();
880880
@@ -1329,6 +1329,7 @@ void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
13291329void simplecpp::TokenList::constFoldQuestionOp (Token **tok1)
13301330{
13311331 bool gotoTok1 = false ;
1332+ // NOLINTNEXTLINE(misc-const-correctness) - technically correct but used to access non-const data
13321333 for (Token *tok = *tok1; tok && tok->op != ' )' ; tok = gotoTok1 ? *tok1 : tok->next ) {
13331334 gotoTok1 = false ;
13341335 if (tok->str () != " ?" )
@@ -1508,7 +1509,12 @@ namespace simplecpp {
15081509 }
15091510
15101511 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)
15121518 }
15131519
15141520 ~Macro () {
@@ -1945,6 +1951,7 @@ namespace simplecpp {
19451951 }
19461952 }
19471953
1954+ // NOLINTNEXTLINE(misc-const-correctness) - technically correct but used to access non-const data
19481955 Token * const output_end_1 = output.back ();
19491956
19501957 const Token *valueToken2;
@@ -2250,7 +2257,7 @@ namespace simplecpp {
22502257 const bool canBeConcatenatedStringOrChar = isStringLiteral_ (A->str ()) || isCharLiteral_ (A->str ());
22512258 const bool unexpectedA = (!A->name && !A->number && !A->str ().empty () && !canBeConcatenatedWithEqual && !canBeConcatenatedStringOrChar);
22522259
2253- Token * const B = tok->next ->next ;
2260+ const Token * const B = tok->next ->next ;
22542261 if (!B->name && !B->number && B->op && !B->isOneOf (" #=" ))
22552262 throw invalidHashHash::unexpectedToken (tok->location , name (), B);
22562263
@@ -2528,11 +2535,11 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
25282535 for (simplecpp::Token *tok = expr.front (); tok; tok = tok->next ) {
25292536 if (tok->str () != " sizeof" )
25302537 continue ;
2531- simplecpp::Token *tok1 = tok->next ;
2538+ const simplecpp::Token *tok1 = tok->next ;
25322539 if (!tok1) {
25332540 throw std::runtime_error (" missing sizeof argument" );
25342541 }
2535- simplecpp::Token *tok2 = tok1->next ;
2542+ const simplecpp::Token *tok2 = tok1->next ;
25362543 if (!tok2) {
25372544 throw std::runtime_error (" missing sizeof argument" );
25382545 }
@@ -2547,7 +2554,7 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
25472554 }
25482555
25492556 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 ) {
25512558 if ((typeToken->str () == " unsigned" || typeToken->str () == " signed" ) && typeToken->next ->name )
25522559 continue ;
25532560 if (typeToken->str () == " *" && type.find (' *' ) != std::string::npos)
@@ -2598,11 +2605,11 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
25982605 for (simplecpp::Token *tok = expr.front (); tok; tok = tok->next ) {
25992606 if (tok->str () != HAS_INCLUDE)
26002607 continue ;
2601- simplecpp::Token *tok1 = tok->next ;
2608+ const simplecpp::Token *tok1 = tok->next ;
26022609 if (!tok1) {
26032610 throw std::runtime_error (" missing __has_include argument" );
26042611 }
2605- simplecpp::Token *tok2 = tok1->next ;
2612+ const simplecpp::Token *tok2 = tok1->next ;
26062613 if (!tok2) {
26072614 throw std::runtime_error (" missing __has_include argument" );
26082615 }
@@ -2620,7 +2627,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
26202627 const bool systemheader = (tok1 && tok1->op == ' <' );
26212628 std::string header;
26222629 if (systemheader) {
2623- simplecpp::Token *tok3 = tok1->next ;
2630+ const simplecpp::Token *tok3 = tok1->next ;
26242631 if (!tok3) {
26252632 throw std::runtime_error (" missing __has_include closing angular bracket" );
26262633 }
@@ -2631,7 +2638,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
26312638 }
26322639 }
26332640
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 )
26352642 header += headerToken->str ();
26362643 } else {
26372644 header = tok1->str ().substr (1U , tok1->str ().size () - 2U );
0 commit comments