[cfe-commits] r137512 - 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
Fri Aug 12 13:56:43 PDT 2011


Author: jyasskin
Date: Fri Aug 12 15:56:43 2011
New Revision: 137512

URL: http://llvm.org/viewvc/llvm-project?rev=137512&view=rev
Log:
Conversions to bool count as integer conversions for the purposes of
the C++0x narrowing error.

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=137512&r1=137511&r2=137512&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug 12 15:56:43 2011
@@ -2321,6 +2321,7 @@
   //   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());

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=137512&r1=137511&r2=137512&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 Fri Aug 12 15:56:43 2011
@@ -138,6 +138,12 @@
   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





More information about the cfe-commits mailing list