Hi! 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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2025-11-10 Jakub Jelinek <[email protected]> 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. --- libcpp/directives.cc.jj 2025-08-15 22:31:17.289081163 +0200 +++ libcpp/directives.cc 2025-11-08 09:36:29.186756709 +0100 @@ -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 --- gcc/testsuite/g++.dg/warn/Wkeyword-macro-4.C.jj 2025-08-07 08:47:14.108784105 +0200 +++ gcc/testsuite/g++.dg/warn/Wkeyword-macro-4.C 2025-11-08 09:39:00.091610696 +0100 @@ -104,9 +104,9 @@ #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 --- gcc/testsuite/g++.dg/warn/Wkeyword-macro-5.C.jj 2025-08-07 08:47:14.108784105 +0200 +++ gcc/testsuite/g++.dg/warn/Wkeyword-macro-5.C 2025-11-08 09:39:34.746117872 +0100 @@ -104,9 +104,9 @@ #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 --- gcc/testsuite/g++.dg/warn/Wkeyword-macro-9.C.jj 2025-08-07 08:47:14.109784091 +0200 +++ gcc/testsuite/g++.dg/warn/Wkeyword-macro-9.C 2025-11-08 09:40:00.382753292 +0100 @@ -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 --- gcc/testsuite/g++.dg/warn/Wkeyword-macro-8.C.jj 2025-08-07 08:47:14.109784091 +0200 +++ gcc/testsuite/g++.dg/warn/Wkeyword-macro-8.C 2025-11-08 09:39:47.451937184 +0100 @@ -104,9 +104,9 @@ #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 --- gcc/testsuite/g++.dg/warn/Wkeyword-macro-10.C.jj 2025-08-07 08:47:14.109784091 +0200 +++ gcc/testsuite/g++.dg/warn/Wkeyword-macro-10.C 2025-11-08 09:40:14.254556023 +0100 @@ -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 Jakub
