From f9701c6e8362dc85db1ac98d4e5773affe75b871 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Sat, 10 Jan 2015 18:16:25 +0000 Subject: [PATCH] fix pr18645. Correct logic concerning 'T &&' deduction against lvalues. llvm-svn: 225587 --- clang/lib/Sema/SemaTemplateDeduction.cpp | 47 +++++++++--------------- clang/test/SemaTemplate/deduction.cpp | 5 +++ 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index dd2a4d26979e..90384f0b0a92 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3136,34 +3136,16 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(Sema &S, // are ignored for type deduction. if (ParamType.hasQualifiers()) ParamType = ParamType.getUnqualifiedType(); + + // [...] If P is a reference type, the type referred to by P is + // used for type deduction. const ReferenceType *ParamRefType = ParamType->getAs(); - if (ParamRefType) { - QualType PointeeType = ParamRefType->getPointeeType(); + if (ParamRefType) + ParamType = ParamRefType->getPointeeType(); - // If the argument has incomplete array type, try to complete its type. - if (ArgType->isIncompleteArrayType() && !S.RequireCompleteExprType(Arg, 0)) - ArgType = Arg->getType(); - - // [C++0x] If P is an rvalue reference to a cv-unqualified - // template parameter and the argument is an lvalue, the type - // "lvalue reference to A" is used in place of A for type - // deduction. - if (isa(ParamType)) { - if (!PointeeType.getQualifiers() && - isa(PointeeType) && - Arg->Classify(S.Context).isLValue() && - Arg->getType() != S.Context.OverloadTy && - Arg->getType() != S.Context.BoundMemberTy) - ArgType = S.Context.getLValueReferenceType(ArgType); - } - - // [...] If P is a reference type, the type referred to by P is used - // for type deduction. - ParamType = PointeeType; - } - - // Overload sets usually make this parameter an undeduced - // context, but there are sometimes special circumstances. + // Overload sets usually make this parameter an undeduced context, + // but there are sometimes special circumstances. Typically + // involving a template-id-expr. if (ArgType == S.Context.OverloadTy) { ArgType = ResolveOverloadForDeduction(S, TemplateParams, Arg, ParamType, @@ -3173,12 +3155,17 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(Sema &S, } if (ParamRefType) { + // If the argument has incomplete array type, try to complete its type. + if (ArgType->isIncompleteArrayType() && !S.RequireCompleteExprType(Arg, 0)) + ArgType = Arg->getType(); + // C++0x [temp.deduct.call]p3: - // [...] If P is of the form T&&, where T is a template parameter, and - // the argument is an lvalue, the type A& is used in place of A for - // type deduction. + // If P is an rvalue reference to a cv-unqualified template + // parameter and the argument is an lvalue, the type "lvalue + // reference to A" is used in place of A for type deduction. if (ParamRefType->isRValueReferenceType() && - ParamRefType->getAs() && + !ParamType.getQualifiers() && + isa(ParamType) && Arg->isLValue()) ArgType = S.Context.getLValueReferenceType(ArgType); } else { diff --git a/clang/test/SemaTemplate/deduction.cpp b/clang/test/SemaTemplate/deduction.cpp index c59f10dbb12e..e33d1576da58 100644 --- a/clang/test/SemaTemplate/deduction.cpp +++ b/clang/test/SemaTemplate/deduction.cpp @@ -202,3 +202,8 @@ namespace PR19372 { using T = S; } } + +namespace PR18645 { + template F Quux(F &&f); + auto Baz = Quux(Quux); +}