https://github.com/swote-git updated https://github.com/llvm/llvm-project/pull/155570
>From 36f751e7b92d8907bfe60f3c28748519578097c3 Mon Sep 17 00:00:00 2001 From: swote <[email protected]> Date: Wed, 27 Aug 2025 16:34:13 +0900 Subject: [PATCH 1/6] [clang][test] Add tests for comma operator rejection in preprocessor expressions Add test coverage for comma operator usage in #if preprocessor directives to ensure it continues to be properly rejected across all C++ standard versions. Per CWG 1436, comma operators are not among the permitted operators in preprocessor conditional expressions. Addresses #132822 --- clang/test/Preprocessor/cxx_oper_comma.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 clang/test/Preprocessor/cxx_oper_comma.cpp diff --git a/clang/test/Preprocessor/cxx_oper_comma.cpp b/clang/test/Preprocessor/cxx_oper_comma.cpp new file mode 100644 index 0000000000000..5589024ede01c --- /dev/null +++ b/clang/test/Preprocessor/cxx_oper_comma.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++98 +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++11 +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++14 +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++17 +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++20 +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++23 + +// Test 1: Top-level comma +// expected-error@+1 {{expected end of line in preprocessor expression}} +#if 1, 2 +#endif + +// Test 2: Comma in conditional expression +// expected-error@+1 {{comma operator in operand of #if}} +#if 1 ? 1, 0 : 3 +#endif + +// Test 3: Parenthesized comma +// expected-error@+1 {{comma operator in operand of #if}} +#if (1, 2) +#endif + +// Test 4: Multiple commas +// expected-error@+1 {{expected end of line in preprocessor expression}} +#if 1, 2, 3 +#endif >From 52bc5dbd77f0a8d79aacdad99bb29b2d6c566588 Mon Sep 17 00:00:00 2001 From: swote <[email protected]> Date: Mon, 22 Sep 2025 23:21:54 +0900 Subject: [PATCH 2/6] Add #elif test and CWG 3017 context - Add test coverage for comma operator in #elif directive - Reference CWG 3017 in comments for additional context - Addresses reviewer feedback --- clang/test/Preprocessor/cxx_oper_comma.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/test/Preprocessor/cxx_oper_comma.cpp b/clang/test/Preprocessor/cxx_oper_comma.cpp index 5589024ede01c..39d020e73ebad 100644 --- a/clang/test/Preprocessor/cxx_oper_comma.cpp +++ b/clang/test/Preprocessor/cxx_oper_comma.cpp @@ -10,7 +10,9 @@ #if 1, 2 #endif -// Test 2: Comma in conditional expression +// Test 2: Comma in conditional expression(CWG3017) +// Per CWG 3017, this exact case highlights the specification gap +// where C++ lacks explicit prohibition of comma operators in #if // expected-error@+1 {{comma operator in operand of #if}} #if 1 ? 1, 0 : 3 #endif @@ -24,3 +26,8 @@ // expected-error@+1 {{expected end of line in preprocessor expression}} #if 1, 2, 3 #endif + +// Test 5: Comma in #elif +#if 0 +#elif (1, 2) // expected-error {{comma operator in operand of #if}} +#endif \ No newline at end of file >From 1c32551b53cd0695add34865734ff34353fa6520 Mon Sep 17 00:00:00 2001 From: swote <[email protected]> Date: Mon, 22 Sep 2025 23:32:08 +0900 Subject: [PATCH 3/6] Add test for #if , (leading comma syntax error) --- clang/test/Preprocessor/cxx_oper_comma.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clang/test/Preprocessor/cxx_oper_comma.cpp b/clang/test/Preprocessor/cxx_oper_comma.cpp index 39d020e73ebad..6e3a6112a5217 100644 --- a/clang/test/Preprocessor/cxx_oper_comma.cpp +++ b/clang/test/Preprocessor/cxx_oper_comma.cpp @@ -30,4 +30,9 @@ // Test 5: Comma in #elif #if 0 #elif (1, 2) // expected-error {{comma operator in operand of #if}} +#endif + +// Test 6: Leading comma (syntax error) +// expected-error@+1 {{invalid token at start of a preprocessor expression}} +#if , #endif \ No newline at end of file >From 728f872c41da25524bbb929dcfb5521bcb1d9044 Mon Sep 17 00:00:00 2001 From: swote <[email protected]> Date: Tue, 23 Sep 2025 01:38:56 +0900 Subject: [PATCH 4/6] Add test for #embed limit as a constant expression --- clang/test/Preprocessor/cxx_oper_comma.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/test/Preprocessor/cxx_oper_comma.cpp b/clang/test/Preprocessor/cxx_oper_comma.cpp index 6e3a6112a5217..d963c6b269f53 100644 --- a/clang/test/Preprocessor/cxx_oper_comma.cpp +++ b/clang/test/Preprocessor/cxx_oper_comma.cpp @@ -3,7 +3,8 @@ // RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++14 // RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++17 // RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++20 -// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++23 +// RUN: %clang_cc1 -E -pedantic-errors %s -verify=expected,embed -std=c++23 -Wno-c23-extensions +// RUN: %clang_cc1 -E -pedantic-errors %s -verify=expected,embed -std=c++2c -Wno-c23-extensions // Test 1: Top-level comma // expected-error@+1 {{expected end of line in preprocessor expression}} @@ -35,4 +36,10 @@ // Test 6: Leading comma (syntax error) // expected-error@+1 {{invalid token at start of a preprocessor expression}} #if , +#endif + +// Test 7: Comma in #embed limit parameter (C++23+) +#if defined(__has_embed) && __cplusplus >= 202302L +// embed-error@+1 {{expected ')'}} +#embed "jk.txt" limit(1, 2) #endif \ No newline at end of file >From aa99069c20f08220162b23f998369cbeb0bb9e23 Mon Sep 17 00:00:00 2001 From: swote <[email protected]> Date: Tue, 23 Sep 2025 01:39:50 +0900 Subject: [PATCH 5/6] adding new line --- clang/test/Preprocessor/cxx_oper_comma.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Preprocessor/cxx_oper_comma.cpp b/clang/test/Preprocessor/cxx_oper_comma.cpp index d963c6b269f53..b4c473a84b3a9 100644 --- a/clang/test/Preprocessor/cxx_oper_comma.cpp +++ b/clang/test/Preprocessor/cxx_oper_comma.cpp @@ -42,4 +42,4 @@ #if defined(__has_embed) && __cplusplus >= 202302L // embed-error@+1 {{expected ')'}} #embed "jk.txt" limit(1, 2) -#endif \ No newline at end of file +#endif >From 503b7c6c23335dfcf5178f97ae561d7210019efa Mon Sep 17 00:00:00 2001 From: swote <[email protected]> Date: Tue, 23 Sep 2025 21:23:54 +0900 Subject: [PATCH 6/6] Address reviewer feedback for #embed test Remove defined(__has_embed) check and use since-cxx23 verify prefix to align with C++ DR test conventions. --- clang/test/Preprocessor/cxx_oper_comma.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/test/Preprocessor/cxx_oper_comma.cpp b/clang/test/Preprocessor/cxx_oper_comma.cpp index b4c473a84b3a9..5db803ae41f32 100644 --- a/clang/test/Preprocessor/cxx_oper_comma.cpp +++ b/clang/test/Preprocessor/cxx_oper_comma.cpp @@ -3,8 +3,8 @@ // RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++14 // RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++17 // RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++20 -// RUN: %clang_cc1 -E -pedantic-errors %s -verify=expected,embed -std=c++23 -Wno-c23-extensions -// RUN: %clang_cc1 -E -pedantic-errors %s -verify=expected,embed -std=c++2c -Wno-c23-extensions +// RUN: %clang_cc1 -E -pedantic-errors %s -verify=expected,since-cxx23 -std=c++23 -Wno-c23-extensions +// RUN: %clang_cc1 -E -pedantic-errors %s -verify=expected,since-cxx23 -std=c++2c -Wno-c23-extensions // Test 1: Top-level comma // expected-error@+1 {{expected end of line in preprocessor expression}} @@ -39,7 +39,7 @@ #endif // Test 7: Comma in #embed limit parameter (C++23+) -#if defined(__has_embed) && __cplusplus >= 202302L -// embed-error@+1 {{expected ')'}} +#if __cplusplus >= 202302L +// since-cxx23-error@+1 {{expected ')'}} #embed "jk.txt" limit(1, 2) #endif _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
