[cfe-commits] r138838 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp

Jeffrey Yasskin jyasskin at google.com
Tue Aug 30 15:25:42 PDT 2011


Author: jyasskin
Date: Tue Aug 30 17:25:41 2011
New Revision: 138838

URL: http://llvm.org/viewvc/llvm-project?rev=138838&view=rev
Log:
Fix PR10694: Boolean conversions can be from pointers, and those conversions
aren't considered narrowing conversions.

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

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=138838&r1=138837&r2=138838&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Aug 30 17:25:41 2011
@@ -2340,6 +2340,11 @@
   //   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());

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp?rev=138838&r1=138837&r2=138838&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp Tue Aug 30 17:25:41 2011
@@ -144,6 +144,9 @@
   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





More information about the cfe-commits mailing list