]> granicus.if.org Git - clang/commitdiff
Conversions to bool count as integer conversions for the purposes of
authorJeffrey Yasskin <jyasskin@google.com>
Fri, 12 Aug 2011 20:56:43 +0000 (20:56 +0000)
committerJeffrey Yasskin <jyasskin@google.com>
Fri, 12 Aug 2011 20:56:43 +0000 (20:56 +0000)
the C++0x narrowing error.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137512 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp

index c406ad9840531dd0d61a76cc4c3f9c0591f014b3..e410f2f9a0d7fca40b6032b7f1e023f8700b7de8 100644 (file)
@@ -2321,6 +2321,7 @@ bool InitializationSequence::endsWithNarrowing(ASTContext &Ctx,
   //   the source is a constant expression and the actual value after
   //   conversion will fit into the target type and will produce the original
   //   value when converted back to the original type.
+  case ICK_Boolean_Conversion:  // Bools are integers too.
   case ICK_Integral_Conversion: {
     assert(FromType->isIntegralOrUnscopedEnumerationType());
     assert(ToType->isIntegralOrUnscopedEnumerationType());
index f82e6cac2064605e12979527b6401a5faa47d5ba..c7f61fbd1882398b106dfaa204e5b307bd5d95d0 100644 (file)
@@ -138,6 +138,12 @@ void shrink_int() {
   Agg<int> i2 = {0x7FFFFFFFU};  // OK
   Agg<int> i3 = {0x80000000U};  // expected-error {{ cannot be narrowed }} expected-note {{override}}
   Agg<unsigned int> i4 = {-0x80000000L};  // expected-error {{ cannot be narrowed }} expected-note {{override}}
+
+  // Bool is also an integer type, but conversions to it are a different AST
+  // node.
+  Agg<bool> b1 = {0};  // OK
+  Agg<bool> b2 = {1};  // OK
+  Agg<bool> b3 = {-1};  // expected-error {{ cannot be narrowed }} expected-note {{override}}
 }
 
 // Be sure that type- and value-dependent expressions in templates get the error