diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-09-21 21:55:46 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-09-21 21:55:46 +0000 |
commit | 089c31637f86a97a2cc4f309c7d46ebf5f0ddb8c (patch) | |
tree | f2ae1df8047a65d0ab7c05a097c1e41fa6041c11 /clang/lib/Sema/SemaOverload.cpp | |
parent | 4e9c091dd72b6ec221d71eb928c99f099f5aff41 (diff) | |
download | bcm5719-llvm-089c31637f86a97a2cc4f309c7d46ebf5f0ddb8c.tar.gz bcm5719-llvm-089c31637f86a97a2cc4f309c7d46ebf5f0ddb8c.zip |
PR17295: Do not allow explicit conversion functions to be used in cases where
an additional conversion (other than a qualification conversion) would be
required after the explicit conversion.
Conversely, do allow explicit conversion functions to be used when initializing
a temporary for a reference binding in direct-list-initialization.
llvm-svn: 191150
Diffstat (limited to 'clang/lib/Sema/SemaOverload.cpp')
-rw-r--r-- | clang/lib/Sema/SemaOverload.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 800f9832498..df18752bfa8 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -5829,6 +5829,17 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion, ConvType = Conversion->getConversionType().getNonReferenceType(); } + // Per C++ [over.match.conv]p1, [over.match.ref]p1, an explicit conversion + // operator is only a candidate if its return type is the target type or + // can be converted to the target type with a qualification conversion. + bool ObjCLifetimeConversion; + QualType ToNonRefType = ToType.getNonReferenceType(); + if (Conversion->isExplicit() && + !Context.hasSameUnqualifiedType(ConvType, ToNonRefType) && + !IsQualificationConversion(ConvType, ToNonRefType, /*CStyle*/false, + ObjCLifetimeConversion)) + return; + // Overload resolution is always an unevaluated context. EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated); |