Commit 2c8daff
Automerge: [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:
llvm/llvm-project#137658 (comment)File tree
3 files changed
+51
-2
lines changed- clang
- lib/Sema
- test/Sema
3 files changed
+51
-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 | + | |
11650 | 11659 | | |
11651 | 11660 | | |
11652 | 11661 | | |
| |||
12464 | 12473 | | |
12465 | 12474 | | |
12466 | 12475 | | |
12467 | | - | |
| 12476 | + | |
12468 | 12477 | | |
12469 | 12478 | | |
12470 | 12479 | | |
| |||
12490 | 12499 | | |
12491 | 12500 | | |
12492 | 12501 | | |
| 12502 | + | |
| 12503 | + | |
| 12504 | + | |
| 12505 | + | |
| 12506 | + | |
| 12507 | + | |
| 12508 | + | |
| 12509 | + | |
| 12510 | + | |
| 12511 | + | |
| 12512 | + | |
| 12513 | + | |
| 12514 | + | |
12493 | 12515 | | |
12494 | 12516 | | |
12495 | 12517 | | |
| |||
| 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