[PATCH] D84322: [AST][RecoveryExpr] Part3: Suppress spurious "typecheck_cond_expect_scalar" diagnostic
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 6 00:53:40 PDT 2020
hokein added inline comments.
================
Comment at: clang/test/Sema/error-dependence.c:18
+ // type is required" is not emitted.
+ ptr > f ? ptr : f; // expected-error {{invalid operands to binary expression}}
+}
----------------
sammccall wrote:
> nit: parens would help me understand here :-)
>
> I don't find this example compelling because we should know that "ptr > f" is a boolean.
>
> Can we just have `undefined ? ptr : f`, expecting the only diag to be the undeclared ident?
> I don't find this example compelling because we should know that "ptr > f" is a boolean.
this is a reasonable impression, but in this case, there is no binary-operator `>` -- operands `ptr`, `f` have different types, and invalid for binary operator, instead we build a recovery-expr.
so the AST looks like (added in the dump-recovery.c test as well)
```
ConditionalOperator> '<dependent type>' contains-errors
| |-RecoveryExpr '<dependent type>' contains-errors lvalue
| | |-DeclRefExpr 'int *' lvalue Var 0x8fdb620 'ptr' 'int *'
| | `-DeclRefExpr 'float' lvalue Var 0x8ffd388 'f' 'float'
| |-DeclRefExpr 'int *' lvalue Var 0x8fdb620 'ptr' 'int *'
| `-DeclRefExpr 'float' lvalue Var 0x8ffd388 'f' 'float'
```
> Can we just have undefined ? ptr : f, expecting the only diag to be the undeclared ident?
no unfortunately. the whole statement is being dropped (we don't preserve this in C/C++).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84322/new/
https://reviews.llvm.org/D84322
More information about the cfe-commits
mailing list