diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 37b6c1441..7bff5ffcf 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1995,6 +1995,8 @@ bool Tokenizer::tokenize(std::istream &code, removeRedundantSemicolons(); + simplifyReservedWordNullptr(); + simplifyParameterVoid(); simplifyRedundantConsecutiveBraces(); @@ -2104,14 +2106,6 @@ void Tokenizer::simplifyNull() tok->str("0"); } } - - // nullptr.. - if (isCPP()) { - for (Token *tok = list.front(); tok; tok = tok->next()) { - if (tok->str() == "nullptr") - tok->str("0"); - } - } } void Tokenizer::concatenateNegativeNumber() @@ -2204,6 +2198,16 @@ void Tokenizer::simplifyParameterVoid() } } +void Tokenizer::simplifyReservedWordNullptr() +{ + if (_settings->standards.cpp11) { + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (tok->str() == "nullptr") + tok->str("0"); + } + } +} + void Tokenizer::simplifyRedundantConsecutiveBraces() { // Remove redundant consecutive braces, i.e. '.. { { .. } } ..' -> '.. { .. } ..'. diff --git a/lib/tokenize.h b/lib/tokenize.h index a6e8a582d..5a1e7cbdf 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -463,6 +463,8 @@ public: bool hasComplicatedSyntaxErrorsInTemplates(); + void simplifyReservedWordNullptr(); + /** * Simplify e.g. 'atol("0")' into '0' */ diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6d3789fa9..b9c804a11 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4646,17 +4646,12 @@ private: } void simplify_null() { - { - const char code[] = - "int * p = NULL;\n" - "int * q = __null;\n"; - const char expected[] = - "int * p ; p = 0 ;\nint * q ; q = 0 ;"; - ASSERT_EQUALS(expected, tokenizeAndStringify(code,true)); - } - - ASSERT_EQUALS("( a == nullptr )", tokenizeAndStringify("(a==nullptr)", false, false, Settings::Unspecified, "test.c")); - ASSERT_EQUALS("( ! a )", tokenizeAndStringify("(a==nullptr)", false, false, Settings::Unspecified, "test.cpp")); + const char code[] = + "int * p = NULL;\n" + "int * q = __null;\n"; + const char expected[] = + "int * p ; p = 0 ;\nint * q ; q = 0 ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code,true)); } void simplifyMulAndParens() {