[clang] [Clang][Sema] Reject array prvalue operands (PR #140702)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 21 06:47:28 PDT 2025
================
@@ -7639,6 +7639,8 @@ def warn_param_mismatched_alignment : Warning<
def err_objc_object_assignment : Error<
"cannot assign to class object (%0 invalid)">;
+def err_typecheck_array_prvalue_operand : Error<
+ "array prvalue is not permitted">;
----------------
languagelawyer wrote:
> keeping in mind that `foo{}` could also be behind a macro
I doubt that presenting exact array type vs. just saying "array" would help much in this case. There is `note: expanded from macro` to point that something comes from macro expansion. (Not shown for `err_typecheck_invalid_operands`, BTW!)
> `err_typecheck_invalid_operands` is the better approach here
```c++
int main()
{
using IA = int[];
IA ia = { 1, 2, 3 };
ia + 0.; // error: invalid operands to binary expression ('int[3]' and 'double')
// Where is the problem? in 'int[3]' or in 'double'?
ia + 0; // no error means the issue was in 'double'?
IA{ 1, 2, 3 } + 0; // error: invalid operands to binary expression ('int[3]' and 'int')
// Huh? What about now?
}
```
> But ultimately, `int[]` + `int` is what we should diagnose
The types are not the issue, why give misleading diagnostics?
https://github.com/llvm/llvm-project/pull/140702
More information about the cfe-commits
mailing list