diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index a00398b37..ea6cd9718 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -183,6 +183,19 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri if (ch & 0x80) throw std::runtime_error("The code contains characters that are unhandled"); + if (str.compare(i, 6, "#error") == 0 || str.compare(i, 8, "#warning") == 0) + { + if (str.compare(i, 6, "#error") == 0) + code << "#error"; + + i = str.find("\n", i); + if (i == std::string::npos) + break; + + --i; + continue; + } + // We have finished a line that didn't contain any comment // (the '\n' is swallowed when a // comment is detected) if (ch == '\n' && !suppressionIDs.empty()) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index efd1f44ae..e377a807c 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -78,6 +78,9 @@ private: // #error => don't extract any code TEST_CASE(error1); + // #error with extended chars + TEST_CASE(error2); + // Handling include guards (don't create extra configuration for it) TEST_CASE(includeguard); @@ -419,6 +422,18 @@ private: } + void error2() + { + const char filedata[] = "#error ê\n" + "#warning ê\n" + "123"; + + // Read string.. + std::istringstream istr(filedata); + ASSERT_EQUALS("#error\n\n123", Preprocessor::read(istr)); + } + + void includeguard() { // Handling include guards..