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/2] [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/2] 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 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
