diff options
author | Steve Naroff <snaroff@apple.com> | 2009-04-08 17:05:15 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-04-08 17:05:15 +0000 |
commit | ea4c780da19e11edc9d13a09b51a6eb6b7446e11 (patch) | |
tree | 1ef7aee41579eec9d33ae052c75bafa1ce918739 /clang/lib/Sema | |
parent | 3da1d240ffdcbc8729da9b91ac0a2fa1bd310229 (diff) | |
download | llvm-ea4c780da19e11edc9d13a09b51a6eb6b7446e11.zip llvm-ea4c780da19e11edc9d13a09b51a6eb6b7446e11.tar.gz llvm-ea4c780da19e11edc9d13a09b51a6eb6b7446e11.tar.bz2 |
Sema::CheckConditionalOperands(): Soften pointer/integer mismatch from error->warning.
Fixes <rdar://problem/6762239> [sema] gcc incompatibility; error on incompatible operand types in ?:.
llvm-svn: 68617
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index d442b1f..4f8ad5b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2714,6 +2714,20 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, } } + // GCC compatibility: soften pointer/integer mismatch. + if (RHSTy->isPointerType() && LHSTy->isIntegerType()) { + Diag(QuestionLoc, diag::warn_typecheck_cond_pointer_integer_mismatch) + << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange(); + ImpCastExprToType(LHS, RHSTy); // promote the integer to a pointer. + return RHSTy; + } + if (LHSTy->isPointerType() && RHSTy->isIntegerType()) { + Diag(QuestionLoc, diag::warn_typecheck_cond_pointer_integer_mismatch) + << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange(); + ImpCastExprToType(RHS, LHSTy); // promote the integer to a pointer. + return LHSTy; + } + // Selection between block pointer types is ok as long as they are the same. if (LHSTy->isBlockPointerType() && RHSTy->isBlockPointerType() && Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy)) |