[clang] [clang][Sema] Check conditional branches inside a comma operand (PR #220573)
Aditya Medhane via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 4 13:03:37 PDT 2026
================
@@ -72,3 +72,15 @@ enum E1 comma4(void) {
return ((void)1, 2); // expected-warning {{implicit conversion from 'int' to enumeration type 'enum E1' is invalid in C++}} \
cxx-error {{cannot initialize return object of type 'enum E1' with an rvalue of type 'int'}}
}
+
+// The branches of a conditional operand are each converted to the context
+// type, so a conditional between enumerators of the target type is fine in
+// C++ and must not be diagnosed here either.
+enum E1 comma5(int c) {
+ return ((void)0, c ? E1_One : E1_Zero);
+}
----------------
flash1729 wrote:
the comma path only runs under `!S.getLangOpts().CPlusPlus`, so this change doesn't reach C++ at all. The third RUN line already compiles this file as C++ and comma5 passes clean there (comma6 keeps its `cxx-error`), do we still need a separate test then ?
https://github.com/llvm/llvm-project/pull/220573
More information about the cfe-commits
mailing list