https://github.com/swote-git created https://github.com/llvm/llvm-project/pull/155570
Add test coverage to ensure comma operators remain properly rejected in `#if` directives. Per CWG 1436, comma is not among the permitted operators in preprocessor conditional expressions. This test prevents regressions and clarifies the intended behavior. Addresses #132822 >From 36f751e7b92d8907bfe60f3c28748519578097c3 Mon Sep 17 00:00:00 2001 From: swote <kst7...@gmail.com> Date: Wed, 27 Aug 2025 16:34:13 +0900 Subject: [PATCH] [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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits