diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 8280e96e1..b9c7f17bb 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1838,6 +1838,10 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str defs.erase(line.substr(7)); } + else if (line.compare(0,7,"#error ") == 0) { + error(filePath, linenr, line.substr(7)); + } + ostr << line; } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index a2c5c66e1..3a0e2f10c 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -2828,7 +2828,7 @@ private: const std::string filePath("test.c"); const std::list includePaths; std::map defs; - Preprocessor preprocessor; + Preprocessor preprocessor(NULL, this); // ifdef { @@ -2928,6 +2928,24 @@ private: ASSERT_EQUALS(actual1 + "#undef X\n" + actual1, actual); } + + // missing include + { + errout.str(""); + const std::string code("#include \"missing.h\""); + const std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs)); + ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing.h\" not found.\n", errout.str()); + } + + // #error + { + errout.str(""); + defs.clear(); + const std::string code("#ifndef X\n#error abc\n#endif"); + const std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs)); + ASSERT_EQUALS("\n#error abc\n\n", actual); + ASSERT_EQUALS("[test.c:2]: (error) abc\n", errout.str()); + } } };