12
12
#include " clang/AST/ASTConsumer.h"
13
13
#include " clang/AST/ASTContext.h"
14
14
#include " clang/AST/Decl.h"
15
- #include " clang/AST/DeclBase.h"
16
15
#include " clang/AST/DeclFriend.h"
17
16
#include " clang/AST/DeclTemplate.h"
18
17
#include " clang/AST/Expr.h"
40
39
#include " llvm/ADT/SmallBitVector.h"
41
40
#include " llvm/ADT/SmallString.h"
42
41
#include " llvm/ADT/StringExtras.h"
43
- #include " llvm/Support/Casting.h"
44
42
45
43
#include < iterator>
46
44
#include < optional>
@@ -2716,9 +2714,12 @@ FindAppearedTemplateParamsInAlias(ArrayRef<TemplateArgument> DeducedArgs,
2716
2714
return Results;
2717
2715
}
2718
2716
2719
- bool hasDeclaredDeductionGuides (DeclarationName Name, DeclContext* DC) {
2717
+ bool hasDeclaredDeductionGuides (DeclarationName Name, DeclContext * DC) {
2720
2718
// Check whether we've already declared deduction guides for this template.
2721
2719
// FIXME: Consider storing a flag on the template to indicate this.
2720
+ assert (Name.getNameKind () ==
2721
+ DeclarationName::NameKind::CXXDeductionGuideName &&
2722
+ " name must be a deduction guide name" );
2722
2723
auto Existing = DC->lookup (Name);
2723
2724
for (auto *D : Existing)
2724
2725
if (D->isImplicit ())
@@ -2737,14 +2738,14 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
2737
2738
Context.DeclarationNames .getCXXDeductionGuideName (AliasTemplate),
2738
2739
AliasTemplate->getDeclContext ()))
2739
2740
return ;
2740
- // Unrap the sugar ElaboratedType.
2741
+ // Unwrap the sugared ElaboratedType.
2741
2742
auto RhsType = AliasTemplate->getTemplatedDecl ()
2742
2743
->getUnderlyingType ()
2743
2744
.getSingleStepDesugaredType (Context);
2744
2745
TemplateDecl *Template = nullptr ;
2745
2746
llvm::ArrayRef<TemplateArgument> AliasRhsTemplateArgs;
2746
2747
if (const auto *TST = RhsType->getAs <TemplateSpecializationType>()) {
2747
- // TemplateName in TEST can be a TypeAliasTemplateDecl if
2748
+ // TemplateName in TST can be a TypeAliasTemplateDecl if
2748
2749
// the right hand side of the alias is also a type alias, e.g.
2749
2750
//
2750
2751
// template<typename T>
@@ -2787,7 +2788,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
2787
2788
else if (const auto *ET = RType->getAs <ElaboratedType>())
2788
2789
// explicit deduction guide.
2789
2790
FReturnType = ET->getNamedType ()->getAs <TemplateSpecializationType>();
2790
- assert (FReturnType);
2791
+ assert (FReturnType && " expected to see a return type " );
2791
2792
// Deduce template arguments of the deduction guide f from the RHS of
2792
2793
// the alias.
2793
2794
//
@@ -2812,9 +2813,12 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
2812
2813
// Must initialize n elements, this is required by DeduceTemplateArguments.
2813
2814
SmallVector<DeducedTemplateArgument> DeduceResults (
2814
2815
F->getTemplateParameters ()->size ());
2816
+
2815
2817
// FIXME: DeduceTemplateArguments stops immediately at the first
2816
- // non-deducible template parameter, extend it to continue performing
2817
- // deduction for rest of parameters.
2818
+ // non-deducible template argument. However, this doesn't seem to casue
2819
+ // issues for practice cases, we probably need to extend it to continue
2820
+ // performing deduction for rest of arguments to align with the C++
2821
+ // standard.
2818
2822
SemaRef.DeduceTemplateArguments (
2819
2823
F->getTemplateParameters (), FReturnType->template_arguments (),
2820
2824
AliasRhsTemplateArgs, TDeduceInfo, DeduceResults,
@@ -2902,7 +2906,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
2902
2906
FPrimeTemplateParams.push_back (NewParam);
2903
2907
2904
2908
assert (TemplateArgsForBuildingFPrime[FTemplateParamIdx].isNull () &&
2905
- " InstantiatedArgs must be null before setting" );
2909
+ " The argument must be null before setting" );
2906
2910
TemplateArgsForBuildingFPrime[FTemplateParamIdx] =
2907
2911
Context.getCanonicalTemplateArgument (
2908
2912
Context.getInjectedTemplateArg (NewParam));
@@ -2936,7 +2940,9 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
2936
2940
const auto &D = DeduceResults[Index];
2937
2941
if (D.isNull ()) {
2938
2942
// 2): Non-deduced template parameter has been built already.
2939
- assert (!TemplateArgsForBuildingFPrime[Index].isNull ());
2943
+ assert (!TemplateArgsForBuildingFPrime[Index].isNull () &&
2944
+ " template arguments for non-deduced template parameters should "
2945
+ " be been set!" );
2940
2946
continue ;
2941
2947
}
2942
2948
TemplateArgumentLoc Input = SemaRef.getTrivialTemplateArgumentLoc (
@@ -2956,7 +2962,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
2956
2962
F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation (),
2957
2963
Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
2958
2964
auto *GG = dyn_cast<CXXDeductionGuideDecl>(FPrime);
2959
- // FIXME: implement the assoicated constraint per C++
2965
+ // FIXME: implement the associated constraint per C++
2960
2966
// [over.match.class.deduct]p3.3:
2961
2967
// The associated constraints ([temp.constr.decl]) are the
2962
2968
// conjunction of the associated constraints of g and a
0 commit comments