@@ -4687,6 +4687,25 @@ bool Sema::InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD,
4687
4687
NamedDecl *Pattern = FD;
4688
4688
std::optional<ArrayRef<TemplateArgument>> Innermost;
4689
4689
4690
+ // C++ [dcl.fct.default]p4
4691
+ // For non-template functions, default arguments can be added in later
4692
+ // declarations of a function that inhabit the same scope.
4693
+ //
4694
+ // C++ [dcl.fct.default]p6
4695
+ // Except for member functions of templated classes, the default arguments
4696
+ // in a member function definition that appears outside of the class
4697
+ // definition are added to the set of default arguments provided by the
4698
+ // member function declaration in the class definition; the program is
4699
+ // ill-formed if a default constructor, copy or move constructor, or copy
4700
+ // or move assignment operator is so declared. Default arguments for a
4701
+ // member function of a templated class shall be specified on the initial
4702
+ // declaration of the member function within the templated class.
4703
+ //
4704
+ // We need to collect the template arguments from the context of the function
4705
+ // where the default argument was defined. For a specialization of a function
4706
+ // template explicitly specialized for an implicit instantiation of a class
4707
+ // template, that context is the (implicitly instantiated) declaration in the
4708
+ // definition of the class template specialization.
4690
4709
if (FD->isCXXClassMember () &&
4691
4710
!isGenericLambdaCallOperatorOrStaticInvokerSpecialization (FD)) {
4692
4711
if (FunctionTemplateDecl *FTD = FD->getPrimaryTemplate ()) {
0 commit comments