summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2017-01-19 01:51:39 +0000
committerHans Wennborg <hans@hanshq.net>2017-01-19 01:51:39 +0000
commit2574fd71cbf243821653ec56d4818bc48c2f4be7 (patch)
treecc4ac62901f103186a8a9c82beef6161bc390e97 /lib
parent8ebd0ffeb644635b25bf52e40d021ee807c92f33 (diff)
Merging r291955:
------------------------------------------------------------------------ r291955 | rsmith | 2017-01-13 12:46:54 -0800 (Fri, 13 Jan 2017) | 3 lines PR31606: Generalize our tentative DR resolution for inheriting copy/move constructors to better match the pre-P0136R1 behavior. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_40@292463 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/SemaOverload.cpp54
1 files changed, 28 insertions, 26 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index afdae4ed6d..c66fe7678d 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -5944,6 +5944,28 @@ Sema::AddOverloadCandidate(FunctionDecl *Function,
Candidate.FailureKind = ovl_fail_illegal_constructor;
return;
}
+
+ // C++ [over.match.funcs]p8: (proposed DR resolution)
+ // A constructor inherited from class type C that has a first parameter
+ // of type "reference to P" (including such a constructor instantiated
+ // from a template) is excluded from the set of candidate functions when
+ // constructing an object of type cv D if the argument list has exactly
+ // one argument and D is reference-related to P and P is reference-related
+ // to C.
+ auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(FoundDecl.getDecl());
+ if (Shadow && Args.size() == 1 && Constructor->getNumParams() >= 1 &&
+ Constructor->getParamDecl(0)->getType()->isReferenceType()) {
+ QualType P = Constructor->getParamDecl(0)->getType()->getPointeeType();
+ QualType C = Context.getRecordType(Constructor->getParent());
+ QualType D = Context.getRecordType(Shadow->getParent());
+ SourceLocation Loc = Args.front()->getExprLoc();
+ if ((Context.hasSameUnqualifiedType(P, C) || IsDerivedFrom(Loc, P, C)) &&
+ (Context.hasSameUnqualifiedType(D, P) || IsDerivedFrom(Loc, D, P))) {
+ Candidate.Viable = false;
+ Candidate.FailureKind = ovl_fail_inhctor_slice;
+ return;
+ }
+ }
}
unsigned NumParams = Proto->getNumParams();
@@ -6016,31 +6038,6 @@ Sema::AddOverloadCandidate(FunctionDecl *Function,
}
}
- // C++ [over.best.ics]p4+: (proposed DR resolution)
- // If the target is the first parameter of an inherited constructor when
- // constructing an object of type C with an argument list that has exactly
- // one expression, an implicit conversion sequence cannot be formed if C is
- // reference-related to the type that the argument would have after the
- // application of the user-defined conversion (if any) and before the final
- // standard conversion sequence.
- auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(FoundDecl.getDecl());
- if (Shadow && Args.size() == 1 && !isa<InitListExpr>(Args.front())) {
- bool DerivedToBase, ObjCConversion, ObjCLifetimeConversion;
- QualType ConvertedArgumentType = Args.front()->getType();
- if (Candidate.Conversions[0].isUserDefined())
- ConvertedArgumentType =
- Candidate.Conversions[0].UserDefined.After.getFromType();
- if (CompareReferenceRelationship(Args.front()->getLocStart(),
- Context.getRecordType(Shadow->getParent()),
- ConvertedArgumentType, DerivedToBase,
- ObjCConversion,
- ObjCLifetimeConversion) >= Ref_Related) {
- Candidate.Viable = false;
- Candidate.FailureKind = ovl_fail_inhctor_slice;
- return;
- }
- }
-
if (EnableIfAttr *FailedAttr = CheckEnableIf(Function, Args)) {
Candidate.Viable = false;
Candidate.FailureKind = ovl_fail_enable_if;
@@ -10222,8 +10219,13 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
return DiagnoseOpenCLExtensionDisabled(S, Cand);
case ovl_fail_inhctor_slice:
+ // It's generally not interesting to note copy/move constructors here.
+ if (cast<CXXConstructorDecl>(Fn)->isCopyOrMoveConstructor())
+ return;
S.Diag(Fn->getLocation(),
- diag::note_ovl_candidate_inherited_constructor_slice);
+ diag::note_ovl_candidate_inherited_constructor_slice)
+ << (Fn->getPrimaryTemplate() ? 1 : 0)
+ << Fn->getParamDecl(0)->getType()->isRValueReferenceType();
MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
return;