diff --git a/simplecpp.cpp b/simplecpp.cpp index 2dae2f2..5bd5cac 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -3480,7 +3480,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL inc2.takeTokens(inc1); } - if (!inc2.empty() && inc2.cfront()->op == '<' && inc2.cback()->op == '>') { + if (!inc1.empty() && !inc2.empty() && inc2.cfront()->op == '<' && inc2.cback()->op == '>') { TokenString hdr; // TODO: Sometimes spaces must be added in the string // Somehow preprocessToken etc must be told that the location should be source location not destination location diff --git a/test.cpp b/test.cpp index 1f979dd..d8e359e 100644 --- a/test.cpp +++ b/test.cpp @@ -1829,6 +1829,14 @@ static void missingHeader3() ASSERT_EQUALS("", toString(outputList)); } +static void missingHeader4() +{ + const char code[] = "#/**/include <>\n"; + simplecpp::OutputList outputList; + ASSERT_EQUALS("", preprocess(code, &outputList)); + ASSERT_EQUALS("file0,1,syntax_error,No header in #include\n", toString(outputList)); +} + static void nestedInclude() { const char code[] = "#include \"test.h\"\n"; @@ -3057,6 +3065,7 @@ int main(int argc, char **argv) TEST_CASE(missingHeader1); TEST_CASE(missingHeader2); TEST_CASE(missingHeader3); + TEST_CASE(missingHeader4); TEST_CASE(nestedInclude); TEST_CASE(systemInclude);