llvm-project
b59ab701 - [C] Handle comma operator for implicit int->enum conversions (#138752)

Commit
126 days ago
[C] Handle comma operator for implicit int->enum conversions (#138752) In C++, the type of an enumerator is the type of the enumeration, whereas in C, the type of the enumerator is 'int'. The type of a comma operator is the type of the right-hand operand, which means you can get an implicit conversion with this code in C but not in C++: ``` enum E { Zero }; enum E foo() { return ((void)0, Zero); } ``` We were previously incorrectly diagnosing this code as being incompatible with C++ because the type of the paren expression would be 'int' there, whereas in C++ the type is 'E'. So now we handle the comma operator with special logic when analyzing implicit conversions in C. When analyzing the left-hand operand of a comma operator, we do not need to check for that operand causing an implicit conversion for the entire comma expression. So we only check for that case with the right-hand operand. This addresses a concern brought up post-commit: https://github.com/llvm/llvm-project/pull/137658#issuecomment-2854525259
Author
Parents
Loading