aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-10-16 01:44:21 +0000
committerAnders Carlsson <andersca@mac.com>2009-10-16 01:44:21 +0000
commit04905014fd854979ac12fc31a2b25fca37a93eb4 (patch)
treedef4a211b222e9ef9797fa9be5d4e2f70278da60 /lib
parent24ee804962ecef23eb040083eb668f9fa202e4c0 (diff)
The result type of logical || and && is bool in C++. Fixes PR5206.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84231 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/SemaExpr.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index a946500660..d818a5027e 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4812,9 +4812,16 @@ inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14]
UsualUnaryConversions(lex);
UsualUnaryConversions(rex);
- if (lex->getType()->isScalarType() && rex->getType()->isScalarType())
- return Context.IntTy;
- return InvalidOperands(Loc, lex, rex);
+ if (!lex->getType()->isScalarType() || !rex->getType()->isScalarType())
+ return InvalidOperands(Loc, lex, rex);
+
+ if (Context.getLangOptions().CPlusPlus) {
+ // C++ [expr.log.and]p2
+ // C++ [expr.log.or]p2
+ return Context.BoolTy;
+ }
+
+ return Context.IntTy;
}
/// IsReadonlyProperty - Verify that otherwise a valid l-value expression