llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: yronglin <details> <summary>Changes</summary> This PR marks [P2843R3 - Preprocessing is never undefined](https://wg21.link/P2843) as implemented and add tests. Fixes https://github.com/llvm/llvm-project/issues/145658 --- Full diff: https://github.com/llvm/llvm-project/pull/192073.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+4) - (added) clang/test/Preprocessor/p2843r3.cpp (+35) - (modified) clang/www/cxx_status.html (+1-1) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3e2d287d1eb1f..859b7e999848a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -133,6 +133,10 @@ C++ Language Changes C++2c Feature Support ^^^^^^^^^^^^^^^^^^^^^ +- Implemented `P2843R3 <https://wg21.link/P2843R3>`_ Preprocessing is never undefined. + The constructs it makes ill-formed were already diagnosed by Clang under + ``-pedantic``; no behavior change, just conformance. + C++23 Feature Support ^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/test/Preprocessor/p2843r3.cpp b/clang/test/Preprocessor/p2843r3.cpp new file mode 100644 index 0000000000000..53c272390527c --- /dev/null +++ b/clang/test/Preprocessor/p2843r3.cpp @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -std=c++26 -pedantic -verify -Wno-invalid-pp-token %s +// RUN: %clang_cc1 -std=c++23 -pedantic -verify -Wno-invalid-pp-token %s + +// P2843R3: Preprocessing is never undefined. +// These constructs were previously "undefined behavior" in the preprocessor; +// as of C++26 they are ill-formed (diagnostic required). Clang already +// diagnoses them under -pedantic, so this test just pins that behavior down. + +// [cpp.cond] A macro that expands to 'defined' in a conditional expression. +#define DEFINED defined +#if DEFINED(bar) // expected-warning {{macro expansion producing 'defined' has undefined behavior}} +#endif + +// [cpp.replace.general] A preprocessing directive inside the arguments of a +// function-like macro invocation. +#define FUNCTION_MACRO(...) +FUNCTION_MACRO( + #if 0 // expected-warning {{embedding a directive within macro arguments has undefined behavior}} + #endif +) + +// [cpp.concat] Concatenation that does not form a valid preprocessing token. +#define CONCAT(A, B) A ## B +CONCAT(=, >) // expected-error {{pasting formed '=>', an invalid preprocessing token}} +// expected-error@-1 {{expected unqualified-id}} + +// [cpp.predefined] #undef of a reserved identifier / builtin macro. +#undef defined // expected-error {{'defined' cannot be used as a macro name}} +#undef __DATE__ // expected-warning {{undefining builtin macro}} + +// [cpp.line] #line with a non-positive or out-of-range argument. +#line 0 // expected-warning {{#line directive with zero argument is a GNU extension}} +#line -1 // expected-error {{#line directive requires a positive integer argument}} +#line 2147483647 // ok, largest value required to be accepted +#line 2147483648 // expected-warning {{C requires #line number to be less than 2147483648, allowed as extension}} diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html index 2c834b07f9a8f..4a669ff4da8a1 100755 --- a/clang/www/cxx_status.html +++ b/clang/www/cxx_status.html @@ -330,7 +330,7 @@ <h2 id="cxx26">C++2c implementation status</h2> <tr> <td>Preprocessing is never undefined</td> <td><a href="https://wg21.link/P2843">P2843R3</a></td> - <td class="none" align="center">No</td> + <td class="full" align="center">Clang 23</td> </tr> <!-- Kona, Fall 2025--> <tr> `````````` </details> https://github.com/llvm/llvm-project/pull/192073 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
