Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline Pragma Directive False Positive #369

Merged
merged 1 commit into from
Sep 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,

if (newlines > 0 ) {
const Token * const llTok = lastLineTok();
if (llTok && llTok->op == '#' && llTok->next && llTok->next->str() == "define" && llTok->next->next) {
if (llTok && llTok->op == '#' && llTok->next && (llTok->next->str() == "define" || llTok->next->str() == "pragma") && llTok->next->next) {
multiline += newlines;
location.adjust(s);
continue;
Expand Down
17 changes: 17 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,21 @@ static void define_ifdef()

}

static void pragma_backslash()
{
const char code[] = "#pragma comment (longstring, \\\n"
"\"HEADER\\\n"
"This is a very long string that is\\\n"
"a multi-line string.\\\n"
"How much more do I have to say?\\\n"
"Well, be prepared, because the\\\n"
"story is just beginning. This is a test\\\n"
"string for demonstration purposes. \")\n";

simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code, &outputList));
}

static void dollar()
{
ASSERT_EQUALS("$ab", readfile("$ab"));
Expand Down Expand Up @@ -2917,6 +2932,8 @@ int main(int argc, char **argv)
TEST_CASE(define_va_opt_4);
TEST_CASE(define_va_opt_5);

TEST_CASE(pragma_backslash); // multiline pragma directive

// UB: #ifdef as macro parameter
TEST_CASE(define_ifdef);

Expand Down