diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -1994,10 +1994,6 @@ return getDeductionCandidateKind() == DeductionCandidateKind::Copy; } - bool isAggregateDeductionCandidate() const { - return getDeductionCandidateKind() == DeductionCandidateKind::Aggregate; - } - // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == CXXDeductionGuide; } diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -10,7 +10,6 @@ // //===----------------------------------------------------------------------===// -#include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/Expr.h" @@ -10650,7 +10649,7 @@ return; if (!AllowAggregateDeductionCandidate && - GD->isAggregateDeductionCandidate()) + GD->getDeductionCandidateKind() == DeductionCandidateKind::Aggregate) return; // C++ [over.match.list]p1.2: (second phase list initialization) @@ -10674,10 +10673,10 @@ TmpInits.push_back(DI->getInit()); else TmpInits.push_back(E); - AddTemplateOverloadCandidate(TD, FoundDecl, /*ExplicitArgs*/ nullptr, + AddTemplateOverloadCandidate(TD, FoundDecl, /*ExplicitArgs=*/nullptr, TmpInits, Candidates, SuppressUserConversions, - /*PartialOverloading*/ false, AllowExplicit, + /*PartialOverloading=*/false, AllowExplicit, ADLCallKind::NotADL, {}, true); } else { AddOverloadCandidate(GD, FoundDecl, Inits, Candidates, @@ -10726,18 +10725,21 @@ ElementTypes); if (!CheckInitList.HadError()) { // C++ [over.match.class.deduct]p1.8: - // if e_i is of array type and x_i is a braced-init-list or - // string-literal, T_i is an rvalue reference to the declared type - // of e_i + // if e_i is of array type and x_i is a braced-init-list, T_i is an + // rvalue reference to the declared type of e_i and + // C++ [over.match.class.deduct]p1.9: + // if e_i is of array type and x_i is a bstring-literal, T_i is an + // lvalue reference to the const-qualified declared type of e_i and + // C++ [over.match.class.deduct]p1.10: + // otherwise, T_i is the declared type of e_i for (int i = 0, e = ListInit->getNumInits(); i < e && !isa(ElementTypes[i]); ++i) if (ElementTypes[i]->isArrayType()) { if (isa(ListInit->getInit(i))) ElementTypes[i] = Context.getRValueReferenceType(ElementTypes[i]); - else if (isa(ListInit->getInit(i))) - // This deviates from the wording which is incorrect. - // See https://github.com/cplusplus/draft/issues/3898. + else if (isa( + ListInit->getInit(i)->IgnoreParenImpCasts())) ElementTypes[i] = Context.getLValueReferenceType(ElementTypes[i]); } @@ -10761,7 +10763,7 @@ } else { CXXDeductionGuideDecl *GD = AggregateDeductionCandidates[Hash]; FunctionTemplateDecl *TD = GD->getDescribedFunctionTemplate(); - assert(TD); + assert(TD && "aggregate deduction candidate is function template"); addDeductionCandidate(TD, GD, DeclAccessPair::make(TD, AS_public), OnlyListConstructors, true); } diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7383,7 +7383,7 @@ AddOverloadCandidate( Specialization, FoundDecl, Args, CandidateSet, SuppressUserConversions, PartialOverloading, AllowExplicit, - /*AllowExplicitConversions*/ false, IsADLCandidate, Conversions, PO, + /*AllowExplicitConversions=*/false, IsADLCandidate, Conversions, PO, Info.AggregateDeductionCandidateHasMismatchedArity); } diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2590,11 +2590,11 @@ // In case we were expanding a pack when we attempted to declare deduction // guides, turn off pack expansion for everything we're about to do. - ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1); + ArgumentPackSubstitutionIndexRAII SubstIndex(*this, + /*NewSubstitutionIndex=*/-1); // Create a template instantiation record to track the "instantiation" of // constructors into deduction guides. - // FIXME: Add a kind for this to give more meaningful diagnostics. But can - // this substitution process actually fail? + // FIXME: Add a kind for this to give more meaningful diagnostics. InstantiatingTemplate BuildingDeductionGuides(*this, Loc, Template); if (BuildingDeductionGuides.isInvalid()) return nullptr; @@ -2632,8 +2632,7 @@ ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1); // Create a template instantiation record to track the "instantiation" of // constructors into deduction guides. - // FIXME: Add a kind for this to give more meaningful diagnostics. But can - // this substitution process actually fail? + // FIXME: Add a kind for this to give more meaningful diagnostics. InstantiatingTemplate BuildingDeductionGuides(*this, Loc, Template); if (BuildingDeductionGuides.isInvalid()) return; diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -358,15 +358,14 @@ for (TemplateArgument::pack_iterator XA = X.pack_begin(), XAEnd = X.pack_end(), YA = Y.pack_begin(), YAEnd = Y.pack_end(); - XA != XAEnd; ++XA) { + XA != XAEnd; ++XA, ++YA) { if (YA != YAEnd) { - TemplateArgument Merged = checkDeducedTemplateArguments( - Context, DeducedTemplateArgument(*XA, X.wasDeducedFromArrayBound()), - DeducedTemplateArgument(*YA, Y.wasDeducedFromArrayBound())); - if (Merged.isNull() && !(XA->isNull() && YA->isNull())) - return DeducedTemplateArgument(); - NewPack.push_back(Merged); - ++YA; + TemplateArgument Merged = checkDeducedTemplateArguments( + Context, DeducedTemplateArgument(*XA, X.wasDeducedFromArrayBound()), + DeducedTemplateArgument(*YA, Y.wasDeducedFromArrayBound())); + if (Merged.isNull() && !(XA->isNull() && YA->isNull())) + return DeducedTemplateArgument(); + NewPack.push_back(Merged); } else { NewPack.push_back(*XA); } @@ -993,7 +992,7 @@ TemplateDeductionInfo &Info; unsigned PackElements = 0; bool IsPartiallyExpanded = false; - bool DeducePackIfNotAlreadyDeduced; + bool DeducePackIfNotAlreadyDeduced = false; /// The number of expansions, if we have a fully-expanded pack in this scope. std::optional FixedNumExpansions;