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

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 22 06:50:16 PDT 2020


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84322

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/error-dependence.c


Index: clang/test/Sema/error-dependence.c
===================================================================
--- clang/test/Sema/error-dependence.c
+++ clang/test/Sema/error-dependence.c
@@ -11,3 +11,9 @@
   // or function pointer" is not emitted.
   (*__builtin_classify_type)(1); // expected-error {{builtin functions must be directly called}}
 }
+
+void test2(int* ptr, float f) {
+  // verify diagnostic "used type '<dependent type>' where arithmetic or pointer
+  // type is required" is not emitted.
+  ptr > f ? ptr : f; // expected-error {{invalid operands to binary expression}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -8071,6 +8071,16 @@
   VK = VK_RValue;
   OK = OK_Ordinary;
 
+  if (getLangOpts().CDependence &&
+      (Cond.get()->isTypeDependent() || LHS.get()->isTypeDependent() ||
+       RHS.get()->isTypeDependent())) {
+    assert(!getLangOpts().CPlusPlus);
+    assert(Cond.get()->containsErrors() || LHS.get()->containsErrors() ||
+           RHS.get()->containsErrors() &&
+               "should only occur in error-recovery path.");
+    return Context.DependentTy;
+  }
+
   // The OpenCL operator with a vector condition is sufficiently
   // different to merit its own checker.
   if ((getLangOpts().OpenCL && Cond.get()->getType()->isVectorType()) ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84322.279804.patch
Type: text/x-patch
Size: 1415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200722/74fa6e44/attachment.bin>


More information about the cfe-commits mailing list