diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-10-01 18:44:50 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-10-01 18:44:50 +0000 |
commit | dab60ad68a3a98d687305941a3852e793705f945 (patch) | |
tree | c2274cfc2b12b9a28683b67319dc981e21937402 /lib/Sema/SemaType.cpp | |
parent | 393bd8e185692a451b2ba16bdfc9e7d3543b4217 (diff) |
Implement the C++0x "trailing return type" feature, e.g.,
auto f(int) -> int
from Daniel Wallin!
(With a few minor bug fixes from me).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115322 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaType.cpp')
-rw-r--r-- | lib/Sema/SemaType.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 254eb7984d..542c31abfc 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -994,7 +994,30 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S, &ReturnTypeInfo); break; } - + + // Check for auto functions and trailing return type and adjust the + // return type accordingly. + if (getLangOptions().CPlusPlus0x && D.isFunctionDeclarator()) { + const DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun; + if (T == Context.UndeducedAutoTy) { + if (FTI.TrailingReturnType) { + T = GetTypeFromParser(ParsedType::getFromOpaquePtr(FTI.TrailingReturnType), + &ReturnTypeInfo); + } + else { + Diag(D.getDeclSpec().getTypeSpecTypeLoc(), + diag::err_auto_missing_trailing_return); + T = Context.IntTy; + D.setInvalidType(true); + } + } + else if (FTI.TrailingReturnType) { + Diag(D.getDeclSpec().getTypeSpecTypeLoc(), + diag::err_trailing_return_without_auto); + D.setInvalidType(true); + } + } + if (T.isNull()) return Context.getNullTypeSourceInfo(); @@ -1635,6 +1658,7 @@ namespace { assert(Chunk.Kind == DeclaratorChunk::Function); TL.setLParenLoc(Chunk.Loc); TL.setRParenLoc(Chunk.EndLoc); + TL.setTrailingReturn(!!Chunk.Fun.TrailingReturnType); const DeclaratorChunk::FunctionTypeInfo &FTI = Chunk.Fun; for (unsigned i = 0, e = TL.getNumArgs(), tpi = 0; i != e; ++i) { |