]> granicus.if.org Git - clang/commitdiff
Fix PR10694: Boolean conversions can be from pointers, and those conversions
authorJeffrey Yasskin <jyasskin@google.com>
Tue, 30 Aug 2011 22:25:41 +0000 (22:25 +0000)
committerJeffrey Yasskin <jyasskin@google.com>
Tue, 30 Aug 2011 22:25:41 +0000 (22:25 +0000)
aren't considered narrowing conversions.

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

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

index 7a6134453b5f67001c7b3c1912fcee1512c625c6..06d530f007bc01dc2ee235476798acda2125efb4 100644 (file)
@@ -2340,6 +2340,11 @@ bool InitializationSequence::endsWithNarrowing(ASTContext &Ctx,
   //   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.
+    if (!FromType->isIntegralOrUnscopedEnumerationType()) {
+      // Boolean conversions can be from pointers and pointers to members
+      // [conv.bool], and those aren't considered narrowing conversions.
+      return false;
+    }  // Otherwise, fall through to the integral case.
   case ICK_Integral_Conversion: {
     assert(FromType->isIntegralOrUnscopedEnumerationType());
     assert(ToType->isIntegralOrUnscopedEnumerationType());
index be47cb8fe86ee9a356c96c9e3f7babf9991d814a..08f7e76d56ae2ade44d42f7fb49f01ca6b8fe7aa 100644 (file)
@@ -144,6 +144,9 @@ void shrink_int() {
   Agg<bool> b1 = {0};  // OK
   Agg<bool> b2 = {1};  // OK
   Agg<bool> b3 = {-1};  // expected-error {{ cannot be narrowed }} expected-note {{override}}
+
+  // Conversions from pointers to booleans aren't narrowing conversions.
+  Agg<bool> b = {&b1};  // OK
 }
 
 // Be sure that type- and value-dependent expressions in templates get the error