hokein updated this revision to Diff 296374. hokein added a comment. rebase and add ast-dump test.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D84322/new/ https://reviews.llvm.org/D84322 Files: clang/lib/Sema/SemaExpr.cpp clang/test/AST/ast-dump-recovery.c 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 @@ -7,3 +7,9 @@ // not emitted. s = call(); // expected-error {{too few arguments to function call}} } + +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/test/AST/ast-dump-recovery.c =================================================================== --- clang/test/AST/ast-dump-recovery.c +++ clang/test/AST/ast-dump-recovery.c @@ -71,4 +71,14 @@ // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'some_func' // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1 some_func(), 1; + + // conditional operator + float f; + // CHECK: ConditionalOperator {{.*}} '<dependent type>' contains-errors + // CHECK-NEXT: |-RecoveryExpr {{.*}} '<dependent type>' + // CHECK-NEXT: | |-DeclRefExpr {{.*}} 'int *' lvalue + // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'float' lvalue + // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int *' lvalue + // CHECK-NEXT: `-DeclRefExpr {{.*}} 'float' lvalue + ptr > f ? ptr : f; } Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -8067,6 +8067,16 @@ VK = VK_RValue; OK = OK_Ordinary; + if (Context.isDependenceAllowed() && + (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()) ||
Index: clang/test/Sema/error-dependence.c =================================================================== --- clang/test/Sema/error-dependence.c +++ clang/test/Sema/error-dependence.c @@ -7,3 +7,9 @@ // not emitted. s = call(); // expected-error {{too few arguments to function call}} } + +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/test/AST/ast-dump-recovery.c =================================================================== --- clang/test/AST/ast-dump-recovery.c +++ clang/test/AST/ast-dump-recovery.c @@ -71,4 +71,14 @@ // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'some_func' // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1 some_func(), 1; + + // conditional operator + float f; + // CHECK: ConditionalOperator {{.*}} '<dependent type>' contains-errors + // CHECK-NEXT: |-RecoveryExpr {{.*}} '<dependent type>' + // CHECK-NEXT: | |-DeclRefExpr {{.*}} 'int *' lvalue + // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'float' lvalue + // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int *' lvalue + // CHECK-NEXT: `-DeclRefExpr {{.*}} 'float' lvalue + ptr > f ? ptr : f; } Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -8067,6 +8067,16 @@ VK = VK_RValue; OK = OK_Ordinary; + if (Context.isDependenceAllowed() && + (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()) ||
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits