Skip to content

Commit 1c18356

Browse files
authored
Multiline Pragma Directive False Positive (#369)
When #pragma is a multiline directive, simplecpp doesn't mark the directive as a multiline resulting in a false positive of the end parenthesis ')'.
1 parent 26b6431 commit 1c18356

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

simplecpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
892892

893893
if (newlines > 0 ) {
894894
const Token * const llTok = lastLineTok();
895-
if (llTok && llTok->op == '#' && llTok->next && llTok->next->str() == "define" && llTok->next->next) {
895+
if (llTok && llTok->op == '#' && llTok->next && (llTok->next->str() == "define" || llTok->next->str() == "pragma") && llTok->next->next) {
896896
multiline += newlines;
897897
location.adjust(s);
898898
continue;

test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,21 @@ static void define_ifdef()
924924

925925
}
926926

927+
static void pragma_backslash()
928+
{
929+
const char code[] = "#pragma comment (longstring, \\\n"
930+
"\"HEADER\\\n"
931+
"This is a very long string that is\\\n"
932+
"a multi-line string.\\\n"
933+
"How much more do I have to say?\\\n"
934+
"Well, be prepared, because the\\\n"
935+
"story is just beginning. This is a test\\\n"
936+
"string for demonstration purposes. \")\n";
937+
938+
simplecpp::OutputList outputList;
939+
ASSERT_EQUALS("", preprocess(code, &outputList));
940+
}
941+
927942
static void dollar()
928943
{
929944
ASSERT_EQUALS("$ab", readfile("$ab"));
@@ -2953,6 +2968,8 @@ int main(int argc, char **argv)
29532968
TEST_CASE(define_va_opt_4);
29542969
TEST_CASE(define_va_opt_5);
29552970

2971+
TEST_CASE(pragma_backslash); // multiline pragma directive
2972+
29562973
// UB: #ifdef as macro parameter
29572974
TEST_CASE(define_ifdef);
29582975

0 commit comments

Comments
 (0)