libcpp: Add testcase for CWG2579 [PR120778]

Another easy part from the paper.

Part of the CWG2579 has been already done in an earlier paper (with
test commits by Marek) and the remaining part is implemented correctly,
we diagnose as error when token pasting doesn't form a valid token.

Except that message
pasting """" and """" does not give a valid preprocessing token
looked weird and so I've updated the message to use %< and %> instead
of \" quoting.

2025-08-05  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/120778
	* macro.cc (paste_tokens): Use %< and %> instead of \" in
	diagnostics around %.*s.

	* g++.dg/DRs/dr2579.C: New test.
	* c-c++-common/cpp/va-opt-6.c: Expect ' rather than \" around
	tokens in incorrect pasting diagnostics.
	* gcc.dg/c23-attr-syntax-6.c: Likewise.
	* gcc.dg/cpp/paste12.c: Likewise.
	* gcc.dg/cpp/paste12-2.c: Likewise.
	* gcc.dg/cpp/paste14.c: Likewise.
	* gcc.dg/cpp/paste14-2.c: Likewise.
This commit is contained in:
Jakub Jelinek
2025-08-05 08:21:55 +02:00
committed by Jakub Jelinek
parent 2361b20f7a
commit ab7c16990f
8 changed files with 23 additions and 14 deletions

View File

@@ -1071,7 +1071,7 @@ paste_tokens (cpp_reader *pfile, location_t location,
/* Mandatory error for all apart from assembler. */
if (CPP_OPTION (pfile, lang) != CLK_ASM)
cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0,
"pasting \"%.*s\" and \"%.*s\" does not give "
"pasting %<%.*s%> and %<%.*s%> does not give "
"a valid preprocessing token",
(int) (lhsend - buf), buf,
(int) (end - rhsstart), rhsstart);