aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2012-03-27 18:33:03 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2012-03-27 18:33:03 +0000
commitf78c0f9aaabf32f5b5f8633b0066e611b24640ee (patch)
treefec700cbdc11e2d09b7362889c7ebb9984ee2210 /lib
parent978fc9c485d21ee89b4f0bc77ce1ea55c65c7f12 (diff)
Even more careful consideration of C++11 13.3.3.1p4. Fixes PR12241.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153523 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/SemaOverload.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index be0243403b..661f589099 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -2758,6 +2758,19 @@ Sema::IsQualificationConversion(QualType FromType, QualType ToType,
return UnwrappedAnyPointer && Context.hasSameUnqualifiedType(FromType,ToType);
}
+static bool isFirstArgumentCompatibleWithType(ASTContext &Context,
+ CXXConstructorDecl *Constructor,
+ QualType Type) {
+ const FunctionProtoType *CtorType =
+ Constructor->getType()->getAs<FunctionProtoType>();
+ if (CtorType->getNumArgs() > 0) {
+ QualType FirstArg = CtorType->getArgType(0);
+ if (Context.hasSameUnqualifiedType(Type, FirstArg.getNonReferenceType()))
+ return true;
+ }
+ return false;
+}
+
static OverloadingResult
IsInitializerListConstructorConversion(Sema &S, Expr *From, QualType ToType,
CXXRecordDecl *To,
@@ -2784,15 +2797,19 @@ IsInitializerListConstructorConversion(Sema &S, Expr *From, QualType ToType,
S.isInitListConstructor(Constructor) &&
(AllowExplicit || !Constructor->isExplicit());
if (Usable) {
+ // If the first argument is (a reference to) the target type,
+ // suppress conversions.
+ bool SuppressUserConversions =
+ isFirstArgumentCompatibleWithType(S.Context, Constructor, ToType);
if (ConstructorTmpl)
S.AddTemplateOverloadCandidate(ConstructorTmpl, FoundDecl,
/*ExplicitArgs*/ 0,
From, CandidateSet,
- /*SuppressUserConversions=*/true);
+ SuppressUserConversions);
else
S.AddOverloadCandidate(Constructor, FoundDecl,
From, CandidateSet,
- /*SuppressUserConversions=*/true);
+ SuppressUserConversions);
}
}
@@ -2918,15 +2935,8 @@ IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
if (NumArgs == 1) {
// If the first argument is (a reference to) the target type,
// suppress conversions.
- const FunctionProtoType *CtorType =
- Constructor->getType()->getAs<FunctionProtoType>();
- if (CtorType->getNumArgs() > 0) {
- QualType FirstArg = CtorType->getArgType(0);
- if (S.Context.hasSameUnqualifiedType(ToType,
- FirstArg.getNonReferenceType())) {
- SuppressUserConversions = true;
- }
- }
+ SuppressUserConversions = isFirstArgumentCompatibleWithType(
+ S.Context, Constructor, ToType);
}
}
if (ConstructorTmpl)