[cfe-commits] r84231 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/bool.cpp
Anders Carlsson
andersca at mac.com
Thu Oct 15 18:44:21 PDT 2009
Author: andersca
Date: Thu Oct 15 20:44:21 2009
New Revision: 84231
URL: http://llvm.org/viewvc/llvm-project?rev=84231&view=rev
Log:
The result type of logical || and && is bool in C++. Fixes PR5206.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/bool.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=84231&r1=84230&r2=84231&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct 15 20:44:21 2009
@@ -4812,9 +4812,16 @@
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
Modified: cfe/trunk/test/SemaCXX/bool.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/bool.cpp?rev=84231&r1=84230&r2=84231&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/bool.cpp (original)
+++ cfe/trunk/test/SemaCXX/bool.cpp Thu Oct 15 20:44:21 2009
@@ -16,3 +16,15 @@
bool *b1 = (int *)0; // expected-error{{expected 'bool *'}}
}
+
+// static_assert_arg_is_bool(x) compiles only if x is a bool.
+template <typename T>
+void static_assert_arg_is_bool(T x) {
+ bool* p = &x;
+}
+
+void test2() {
+ int n = 2;
+ static_assert_arg_is_bool(n && 4);
+ static_assert_arg_is_bool(n || 5);
+}
More information about the cfe-commits
mailing list