From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id CB6D43858281; Tue, 24 Jan 2023 22:12:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB6D43858281 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674598328; bh=TgF13iixJigPpZJ4lqU97L93WM8Dxo4a7UHJPm71+xc=; h=From:To:Subject:Date:From; b=gsLWw2uLz1dLYYzJFjSvUBrt3JQ3zx0FMkTrBKtwymhHz/7lsewfb9sEQT78YWH7R yBn6vWDL+FgpZRqTsrtHg6whRNSoCGZVJ9QRLv0Z7padEMl4bBPdhdlnO+oUUefw68 5ysDnmKrLF/ey1urC8R+drvFyX0ItO1MI1lGy0c4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5335] c++: "" #pragma at BOF [PR108504] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 39ade88fa1632c659c5c4ed065fa2b62d16a8670 X-Git-Newrev: 327d45c57ebd2655a7599df0f01b8b5e2f82eda7 Message-Id: <20230124221208.CB6D43858281@sourceware.org> Date: Tue, 24 Jan 2023 22:12:08 +0000 (GMT) List-Id: https://gcc.gnu.org/g:327d45c57ebd2655a7599df0f01b8b5e2f82eda7 commit r13-5335-g327d45c57ebd2655a7599df0f01b8b5e2f82eda7 Author: Jason Merrill Date: Tue Jan 24 16:26:50 2023 -0500 c++: "" #pragma at BOF [PR108504] 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. Diff: --- gcc/cp/parser.cc | 2 +- gcc/testsuite/g++.dg/ext/pragma1.C | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index b38c22e9a3d..07ec0e14491 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -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 index 00000000000..bb258dac9a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/pragma1.C @@ -0,0 +1,4 @@ +// PR c++/108504 + +"1" // { dg-error "" } +#pragma GCC diagnostic push