diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2011-08-30 22:25:41 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2011-08-30 22:25:41 +0000 |
commit | b89d5ed785e2eb7dd64aa38d481d939155f62c41 (patch) | |
tree | 5ae0010010c22c578907a6917a3a35f6df7c7c53 | |
parent | e5a54b600f74dcb6cca27543df2757115711d80a (diff) |
Fix PR10694: Boolean conversions can be from pointers, and those conversions
aren't considered narrowing conversions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138838 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaInit.cpp | 5 | ||||
-rw-r--r-- | test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp | 3 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 7a6134453b..06d530f007 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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()); diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp index be47cb8fe8..08f7e76d56 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp @@ -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 |