diff options
| author | Faisal Vali <faisalv@yahoo.com> | 2013-11-01 02:01:01 +0000 |
|---|---|---|
| committer | Faisal Vali <faisalv@yahoo.com> | 2013-11-01 02:01:01 +0000 |
| commit | b9657033ccd50504021b63757b92c1e7f4e69993 (patch) | |
| tree | 1a8496d2a732aa6848ccf8238f2f7be77899b4f3 /clang/lib | |
| parent | 2335879ff185f10449c09445fb6189a578fbac56 (diff) | |
| download | bcm5719-llvm-b9657033ccd50504021b63757b92c1e7f4e69993.tar.gz bcm5719-llvm-b9657033ccd50504021b63757b92c1e7f4e69993.zip | |
Support return type deduction for templates in -fdelayed-template-parsing (microsoft) mode
Please see http://llvm-reviews.chandlerc.com/D2053 for discussion and Richard's stamp.
llvm-svn: 193849
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Parse/ParseCXXInlineMethods.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Parse/Parser.cpp | 23 |
2 files changed, 26 insertions, 3 deletions
diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp index 863a09e89d3..0c8ace59e35 100644 --- a/clang/lib/Parse/ParseCXXInlineMethods.cpp +++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp @@ -109,13 +109,15 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, return FnD; } - + // In delayed template parsing mode, if we are within a class template // or if we are about to parse function member template then consume // the tokens and store them for parsing at the end of the translation unit. if (getLangOpts().DelayedTemplateParsing && DefinitionKind == FDK_Definition && - !D.getDeclSpec().isConstexprSpecified() && + !D.getDeclSpec().isConstexprSpecified() && + !(FnD && getFunctionDecl(FnD) && + getFunctionDecl(FnD)->getResultType()->getContainedAutoType()) && ((Actions.CurContext->isDependentContext() || (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate && TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization)) && diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index d95546af8ab..84aad4101fb 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -919,6 +919,26 @@ Parser::ParseDeclarationOrFunctionDefinition(ParsedAttributesWithRange &attrs, } } + +static inline bool isFunctionDeclaratorRequiringReturnTypeDeduction( + const Declarator &D) { + if (!D.isFunctionDeclarator() || !D.getDeclSpec().containsPlaceholderType()) + return false; + for (unsigned I = 0, E = D.getNumTypeObjects(); I != E; ++I) { + unsigned chunkIndex = E - I - 1; + const DeclaratorChunk &DeclType = D.getTypeObject(chunkIndex); + if (DeclType.Kind == DeclaratorChunk::Function) { + const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; + if (!FTI.hasTrailingReturnType()) + return true; + QualType TrailingRetType = FTI.getTrailingReturnType().get(); + return TrailingRetType->getCanonicalTypeInternal() + ->getContainedAutoType(); + } + } + return false; +} + /// ParseFunctionDefinition - We parsed and verified that the specified /// Declarator is well formed. If this is a K&R-style function, read the /// parameters declaration-list, then start the compound-statement. @@ -992,7 +1012,8 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, // tokens and store them for late parsing at the end of the translation unit. if (getLangOpts().DelayedTemplateParsing && Tok.isNot(tok::equal) && TemplateInfo.Kind == ParsedTemplateInfo::Template && - !D.getDeclSpec().isConstexprSpecified()) { + !D.getDeclSpec().isConstexprSpecified() && + !isFunctionDeclaratorRequiringReturnTypeDeduction(D)) { MultiTemplateParamsArg TemplateParameterLists(*TemplateInfo.TemplateParams); ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope); |

