c++: "" #pragma at BOF [PR108504]
authorJason Merrill <jason@redhat.com>
Tue, 24 Jan 2023 21:26:50 +0000 (16:26 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 24 Jan 2023 22:11:52 +0000 (17:11 -0500)
Since r11-2095 we pass flags to cp_lexer_get_preprocessor_token, and
cp_lexer_new_main passes C_LEX_STRING_NO_JOIN when lexing most of the
translation unit, but doesn't do that for the very first token; as a
result, if the first token is a string literal, we try to join strings and
get confused if that encounters a pragma.

PR c++/108504

gcc/cp/ChangeLog:

* parser.cc (cp_lexer_new_main): Pass C_LEX_STRING_NO_JOIN for first
token, too.

gcc/testsuite/ChangeLog:

* g++.dg/ext/pragma1.C: New test.

gcc/cp/parser.cc
gcc/testsuite/g++.dg/ext/pragma1.C [new file with mode: 0644]

index b38c22e..07ec0e1 100644 (file)
@@ -705,7 +705,7 @@ cp_lexer_new_main (void)
   /* It's possible that parsing the first pragma will load a PCH file,
      which is a GC collection point.  So we have to do that before
      allocating any memory.  */
-  cp_lexer_get_preprocessor_token (0, &token);
+  cp_lexer_get_preprocessor_token (C_LEX_STRING_NO_JOIN, &token);
   cp_parser_initial_pragma (&token);
   c_common_no_more_pch ();
 
diff --git a/gcc/testsuite/g++.dg/ext/pragma1.C b/gcc/testsuite/g++.dg/ext/pragma1.C
new file mode 100644 (file)
index 0000000..bb258da
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/108504
+
+"1"                            // { dg-error "" }
+#pragma GCC diagnostic push