[PATCH] D84322: [AST][RecoveryExpr] Part3: Suppress spurious "typecheck_cond_expect_scalar" diagnostic

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 6 01:00:46 PDT 2020


sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang/test/AST/ast-dump-recovery.c:75
+
+  // conditional operator
+  float f;
----------------
add to comment: (comparison is invalid)


================
Comment at: clang/test/AST/ast-dump-recovery.c:83
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'float' lvalue
+  ptr > f ? ptr : f;
 }
----------------
again - parens


================
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}}
+}
----------------
hokein wrote:
> 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++). 
`undefined() ? ptr : f` then?


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