@@ -10124,23 +10124,6 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
10124
10124
Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_auto_fn_virtual);
10125
10125
}
10126
10126
10127
- if (getLangOpts().CPlusPlus14 &&
10128
- (NewFD->isDependentContext() ||
10129
- (isFriend && CurContext->isDependentContext())) &&
10130
- NewFD->getReturnType()->isUndeducedType()) {
10131
- // If the function template is referenced directly (for instance, as a
10132
- // member of the current instantiation), pretend it has a dependent type.
10133
- // This is not really justified by the standard, but is the only sane
10134
- // thing to do.
10135
- // FIXME: For a friend function, we have not marked the function as being
10136
- // a friend yet, so 'isDependentContext' on the FD doesn't work.
10137
- const FunctionProtoType *FPT =
10138
- NewFD->getType()->castAs<FunctionProtoType>();
10139
- QualType Result = SubstAutoTypeDependent(FPT->getReturnType());
10140
- NewFD->setType(Context.getFunctionType(Result, FPT->getParamTypes(),
10141
- FPT->getExtProtoInfo()));
10142
- }
10143
-
10144
10127
// C++ [dcl.fct.spec]p3:
10145
10128
// The inline specifier shall not appear on a block scope function
10146
10129
// declaration.
@@ -12112,6 +12095,35 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
12112
12095
12113
12096
CheckConstPureAttributesUsage(*this, NewFD);
12114
12097
12098
+ // C++ [dcl.spec.auto.general]p12:
12099
+ // Return type deduction for a templated function with a placeholder in its
12100
+ // declared type occurs when the definition is instantiated even if the
12101
+ // function body contains a return statement with a non-type-dependent
12102
+ // operand.
12103
+ //
12104
+ // C++ [temp.dep.expr]p3:
12105
+ // An id-expression is type-dependent if it is a template-id that is not a
12106
+ // concept-id and is dependent; or if its terminal name is:
12107
+ // - [...]
12108
+ // - associated by name lookup with one or more declarations of member
12109
+ // functions of a class that is the current instantiation declared with a
12110
+ // return type that contains a placeholder type,
12111
+ // - [...]
12112
+ //
12113
+ // If this is a templated function with a placeholder in its return type,
12114
+ // make the placeholder type dependent since it won't be deduced until the
12115
+ // definition is instantiated. We do this here because it needs to happen
12116
+ // for implicitly instantiated member functions/member function templates.
12117
+ if (getLangOpts().CPlusPlus14 &&
12118
+ (NewFD->isDependentContext() &&
12119
+ NewFD->getReturnType()->isUndeducedType())) {
12120
+ const FunctionProtoType *FPT =
12121
+ NewFD->getType()->castAs<FunctionProtoType>();
12122
+ QualType NewReturnType = SubstAutoTypeDependent(FPT->getReturnType());
12123
+ NewFD->setType(Context.getFunctionType(NewReturnType, FPT->getParamTypes(),
12124
+ FPT->getExtProtoInfo()));
12125
+ }
12126
+
12115
12127
// C++11 [dcl.constexpr]p8:
12116
12128
// A constexpr specifier for a non-static member function that is not
12117
12129
// a constructor declares that member function to be const.
0 commit comments