
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
14 lines
309 B
C
14 lines
309 B
C
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
|
|
static char *test1(int cf) {
|
|
return cf ? "abc" : 0;
|
|
}
|
|
static char *test2(int cf) {
|
|
return cf ? 0 : "abc";
|
|
}
|
|
|
|
int baz(void) {
|
|
int f;
|
|
return ((void)0, f = 1.4f); // expected-warning {{implicit conversion from 'float' to 'int' changes value from 1.4 to 1}}
|
|
}
|