]> granicus.if.org Git - clang/commitdiff
treat bool literals as constatnt expressions.
authorAnders Carlsson <andersca@mac.com>
Sat, 23 Aug 2008 21:12:35 +0000 (21:12 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 23 Aug 2008 21:12:35 +0000 (21:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55255 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/SemaCXX/bool.cpp [new file with mode: 0644]

index b004bde7bd286a339d350b6ce99ff784184e81da..5107a5643c9bc6c1d8b606a42c501d7cf2122684 100644 (file)
@@ -720,6 +720,13 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
     Result.setIsUnsigned(!getType()->isSignedIntegerType());
     break;
   }
+  case CXXBoolLiteralExprClass: {
+    const CXXBoolLiteralExpr *BL = cast<CXXBoolLiteralExpr>(this);
+    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
+    Result = BL->getValue();
+    Result.setIsUnsigned(!getType()->isSignedIntegerType());
+    break;
+  }
   case CXXZeroInitValueExprClass:
     Result.clear();
     break;
diff --git a/test/SemaCXX/bool.cpp b/test/SemaCXX/bool.cpp
new file mode 100644 (file)
index 0000000..e35495a
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang -fsyntax-only -verify %s 
+
+// Bool literals can be enum values.
+enum {
+  ReadWrite = false,
+  ReadOnly = true
+};