diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 842e1492f..1d300ecb5 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -2765,7 +2765,7 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file // defining a macro.. if (line.compare(0, 8, "#define ") == 0) { PreprocessorMacro *macro = new PreprocessorMacro(line.substr(8)); - if (macro->name().empty()) { + if (macro->name().empty() || macro->name() == "NULL") { delete macro; } else if (macro->name() == "BOOST_FOREACH") { // BOOST_FOREACH is currently too complex to parse, so skip it. diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 9a328e08b..9d063b21f 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -182,6 +182,7 @@ private: TEST_CASE(macro_linenumbers); TEST_CASE(macro_nopar); TEST_CASE(macro_switchCase); + TEST_CASE(macro_NULL); // skip #define NULL .. it is replaced in the tokenizer TEST_CASE(string1); TEST_CASE(string2); TEST_CASE(string3); @@ -2084,6 +2085,11 @@ private: } } + void macro_NULL() { + ASSERT_EQUALS("\n$0", OurPreprocessor::expandMacros("#define null 0\nnull")); + ASSERT_EQUALS("\nNULL", OurPreprocessor::expandMacros("#define NULL 0\nNULL")); + } + void string1() { const char filedata[] = "int main()" "{"