]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++, libcpp: Implement CWG3053
authorJakub Jelinek <jakub@redhat.com>
Mon, 10 Nov 2025 10:34:20 +0000 (11:34 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 10 Nov 2025 10:34:20 +0000 (11:34 +0100)
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.

gcc/testsuite/g++.dg/warn/Wkeyword-macro-10.C
gcc/testsuite/g++.dg/warn/Wkeyword-macro-4.C
gcc/testsuite/g++.dg/warn/Wkeyword-macro-5.C
gcc/testsuite/g++.dg/warn/Wkeyword-macro-8.C
gcc/testsuite/g++.dg/warn/Wkeyword-macro-9.C
libcpp/directives.cc

index e6fafcd1a3054672d3c2d30ff4fc2a497a48c4d4..ec8c95ea63a7d4fa2ec9a377eb10889c9b13bf81 100644 (file)
@@ -17,7 +17,7 @@
 #undef inline                          // { dg-warning "undefining keyword 'inline'" }
 #define inline __inline__ __attribute__((__always_inline__))   // { dg-warning "keyword 'inline' defined as macro" }
 #define likely(a) a
-#undef likely                          // { dg-warning "undefining keyword 'likely'" "" { target c++20 } }
+#undef likely
 #define unlikely(a, b, c) a + b + c
 #define unlikely(a, b, c) a + b + c
-#undef unlikely                                // { dg-warning "undefining keyword 'unlikely'" "" { target c++20 } }
+#undef unlikely
index 9ff974dfc1e16b787b4b688c139d15e409dc54a8..4fde3ae36d183c916f1ee05df7f9bfbc46f72fd7 100644 (file)
 #undef deprecated                      // { dg-error "undefining keyword 'deprecated'" "" { target c++26 } }
 #undef fallthrough                     // { dg-error "undefining keyword 'fallthrough'" "" { target c++26 } }
 #undef indeterminate
-#undef likely                          // { dg-error "undefining keyword 'likely'" "" { target c++26 } }
+#undef likely
 #undef maybe_unused                    // { dg-error "undefining keyword 'maybe_unused'" "" { target c++26 } }
 #undef nodiscard                       // { dg-error "undefining keyword 'nodiscard'" "" { target c++26 } }
 #undef noreturn                                // { dg-error "undefining keyword 'noreturn'" "" { target c++26 } }
 #undef no_unique_address               // { dg-error "undefining keyword 'no_unique_address'" "" { target c++26 } }
-#undef unlikely                                // { dg-error "undefining keyword 'unlikely'" "" { target c++26 } }
+#undef unlikely
index 657797b5603cd5ebf4d099350d4edd17d6b6c699..13b3b68386d8bc404237448096fa9bb42f89108e 100644 (file)
 #undef deprecated                      // { dg-warning "undefining keyword 'deprecated'" "" { target c++26 } }
 #undef fallthrough                     // { dg-warning "undefining keyword 'fallthrough'" "" { target c++26 } }
 #undef indeterminate
-#undef likely                          // { dg-warning "undefining keyword 'likely'" "" { target c++26 } }
+#undef likely
 #undef maybe_unused                    // { dg-warning "undefining keyword 'maybe_unused'" "" { target c++26 } }
 #undef nodiscard                       // { dg-warning "undefining keyword 'nodiscard'" "" { target c++26 } }
 #undef noreturn                                // { dg-warning "undefining keyword 'noreturn'" "" { target c++26 } }
 #undef no_unique_address               // { dg-warning "undefining keyword 'no_unique_address'" "" { target c++26 } }
-#undef unlikely                                // { dg-warning "undefining keyword 'unlikely'" "" { target c++26 } }
+#undef unlikely
index 7dcc37716d8831ef6275d70dc290ad52284432a7..b9b365e246c88e6182ef1d776ea3a332d6837589 100644 (file)
 #undef deprecated                      // { dg-warning "undefining keyword 'deprecated'" "" { target c++14 } }
 #undef fallthrough                     // { dg-warning "undefining keyword 'fallthrough'" "" { target c++17 } }
 #undef indeterminate
-#undef likely                          // { dg-warning "undefining keyword 'likely'" "" { target c++20 } }
+#undef likely
 #undef maybe_unused                    // { dg-warning "undefining keyword 'maybe_unused'" "" { target c++17 } }
 #undef nodiscard                       // { dg-warning "undefining keyword 'nodiscard'" "" { target c++17 } }
 #undef noreturn                                // { dg-warning "undefining keyword 'noreturn'" "" { target c++11 } }
 #undef no_unique_address               // { dg-warning "undefining keyword 'no_unique_address'" "" { target c++20 } }
-#undef unlikely                                // { dg-warning "undefining keyword 'unlikely'" "" { target c++20 } }
+#undef unlikely
index 741cdee6840e4160cbef15d669dff8476e00c0d5..1145c650cdf6047bb3d30ef929e50ebe1311ea20 100644 (file)
@@ -17,6 +17,6 @@
 #undef inline                          // { dg-error "undefining keyword 'inline'" "" { target c++26 } }
 #define inline __inline__ __attribute__((__always_inline__))   // { dg-error "keyword 'inline' defined as macro" "" { target c++26 } }
 #define likely(a) a
-#undef likely                          // { dg-error "undefining keyword 'likely'" "" { target c++26 } }
+#undef likely
 #define unlikely(a, b, c) a + b + c
 #define unlikely(a, b, c) a + b + c
index b6dd36a88c529a2720e3cc9d64b4eeedafcf3f50..b4994ca43601d5d13375a959c552c960f10a9458 100644 (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