Commit 4c900c6
committed
[C] Handle comma operator for implicit int->enum conversions
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:
llvm#137658 (comment)1 parent aec3929 commit 4c900c6
File tree
3 files changed
+55
-2
lines changed- clang
- lib/Sema
- test/Sema
3 files changed
+55
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11647 | 11647 | | |
11648 | 11648 | | |
11649 | 11649 | | |
| 11650 | + | |
| 11651 | + | |
| 11652 | + | |
| 11653 | + | |
| 11654 | + | |
| 11655 | + | |
| 11656 | + | |
| 11657 | + | |
| 11658 | + | |
| 11659 | + | |
| 11660 | + | |
| 11661 | + | |
| 11662 | + | |
| 11663 | + | |
| 11664 | + | |
| 11665 | + | |
| 11666 | + | |
| 11667 | + | |
| 11668 | + | |
| 11669 | + | |
| 11670 | + | |
| 11671 | + | |
| 11672 | + | |
11650 | 11673 | | |
11651 | 11674 | | |
11652 | 11675 | | |
| |||
12464 | 12487 | | |
12465 | 12488 | | |
12466 | 12489 | | |
12467 | | - | |
| 12490 | + | |
12468 | 12491 | | |
12469 | 12492 | | |
12470 | 12493 | | |
| |||
12490 | 12513 | | |
12491 | 12514 | | |
12492 | 12515 | | |
| 12516 | + | |
| 12517 | + | |
| 12518 | + | |
12493 | 12519 | | |
12494 | 12520 | | |
12495 | 12521 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
0 commit comments