[all-commits] [llvm/llvm-project] b59ab7: [C] Handle comma operator for implicit int->enum c...
Aaron Ballman via All-commits
all-commits at lists.llvm.org
Wed May 7 07:05:21 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b59ab701e94cce455a53358cbe5082a3efb58fbf
https://github.com/llvm/llvm-project/commit/b59ab701e94cce455a53358cbe5082a3efb58fbf
Author: Aaron Ballman <aaron at aaronballman.com>
Date: 2025-05-07 (Wed, 07 May 2025)
Changed paths:
M clang/lib/Sema/SemaChecking.cpp
M clang/test/Sema/implicit-cast.c
M clang/test/Sema/implicit-int-enum-conversion.c
Log Message:
-----------
[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
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list