Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,

if (cback() && cback()->location.line == location.line && cback()->previous && cback()->previous->op == '#') {
const Token* const ppTok = cback()->previous;
if (ppTok->next && (ppTok->next->str() == "error" || ppTok->next->str() == "warning")) {
// #error/#warning directive => '#' is the first token on the line (not the stringizing operator in a #define)
if (ppTok->next && (ppTok->next->str() == "error" || ppTok->next->str() == "warning") && isLastLinePreprocessor(2) == ppTok) {
readErrorText(stream, ch, location);
continue;
}
Expand Down
12 changes: 12 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,17 @@ static void error8()
ASSERT_EQUALS("file0,1,#error,#error blabla\n", toString(outputList));
}

static void error9()
{
// #error and #warning in a #define is the stringizing operator, not a directive
const char code[] = "#define A(error) f(#error); break\n"
"#define B(warning) g(#warning); x\n"
"A(e1) B(w1)\n";
simplecpp::OutputList outputList;
ASSERT_EQUALS("\n\nf ( \"e1\" ) ; break g ( \"w1\" ) ; x", preprocess(code, &outputList));
ASSERT_EQUALS("", toString(outputList));
}

static void garbage()
{
simplecpp::OutputList outputList;
Expand Down Expand Up @@ -6094,6 +6105,7 @@ static void runTests(int argc, char **argv, Input input)
TEST_CASE(error6);
TEST_CASE(error7);
TEST_CASE(error8);
TEST_CASE(error9);

TEST_CASE(garbage);
TEST_CASE(garbage_endif);
Expand Down
Loading