c++, libcpp: Implement CWG3053

The following patch implements CWG3053 approved in Kona, where it is now
valid not just to #define likely(a) or #define unlikely(a, b, c) but also
to #undef likely or #undef unlikely.

2025-11-10  Jakub Jelinek  <jakub@redhat.com>

libcpp/
	* directives.cc: Implement CWG3053.
	(do_undef): Don't pedwarn or warn about #undef likely or #undef
	unlikely.
gcc/testsuite/
	* g++.dg/warn/Wkeyword-macro-4.C: Don't diagnose for #undef likely
	or #undef unlikely.
	* g++.dg/warn/Wkeyword-macro-5.C: Likewise.
	* g++.dg/warn/Wkeyword-macro-9.C: Likewise.
	* g++.dg/warn/Wkeyword-macro-8.C: Likewise.
	* g++.dg/warn/Wkeyword-macro-10.C: Likewise.
This commit is contained in:
Jakub Jelinek
2025-11-10 11:34:20 +01:00
committed by Jakub Jelinek
parent 52fc9f01da
commit 611fc65050
6 changed files with 17 additions and 12 deletions

View File

@@ -740,9 +740,14 @@ do_undef (cpp_reader *pfile)
&& !CPP_OPTION (pfile, suppress_builtin_macro_warnings)
&& cpp_keyword_p (node))
{
if (CPP_OPTION (pfile, cpp_pedantic)
&& CPP_OPTION (pfile, cplusplus)
&& CPP_OPTION (pfile, lang) >= CLK_GNUCXX26)
if (CPP_OPTION (pfile, cplusplus)
&& (strcmp ((const char *) NODE_NAME (node), "likely") == 0
|| strcmp ((const char *) NODE_NAME (node),
"unlikely") == 0))
/* CWG3053: likely and unlikely can be undefined. */;
else if (CPP_OPTION (pfile, cpp_pedantic)
&& CPP_OPTION (pfile, cplusplus)
&& CPP_OPTION (pfile, lang) >= CLK_GNUCXX26)
cpp_pedwarning (pfile, CPP_W_KEYWORD_MACRO,
"undefining keyword %qs", NODE_NAME (node));
else