summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-10-01 18:44:50 +0000
committerDouglas Gregor <dgregor@apple.com>2010-10-01 18:44:50 +0000
commit7fb25418ed726c594ee800378538a96c69e84d4b (patch)
treeebd4b5fca812482aa6686384f20e5d279d6bc695 /clang/lib/Parse/ParseDecl.cpp
parentf14331f5c32c10ddca43ab4d0b3faff2fdfa1367 (diff)
downloadbcm5719-llvm-7fb25418ed726c594ee800378538a96c69e84d4b.tar.gz
bcm5719-llvm-7fb25418ed726c594ee800378538a96c69e84d4b.zip
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). llvm-svn: 115322
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 0a48d4d5507..89b41828b06 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3024,6 +3024,8 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
// lparen is already consumed!
assert(D.isPastIdentifier() && "Should not call before identifier!");
+ ParsedType TrailingReturnType;
+
// This parameter list may be empty.
if (Tok.is(tok::r_paren)) {
if (RequiresArg) {
@@ -3055,6 +3057,11 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
assert(Exceptions.size() == ExceptionRanges.size() &&
"Produced different number of exception types and ranges.");
}
+
+ // Parse trailing-return-type.
+ if (getLang().CPlusPlus0x && Tok.is(tok::arrow)) {
+ TrailingReturnType = ParseTrailingReturnType().get();
+ }
}
// Remember that we parsed a function type, and remember the attributes.
@@ -3069,7 +3076,8 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
Exceptions.data(),
ExceptionRanges.data(),
Exceptions.size(),
- LParenLoc, RParenLoc, D),
+ LParenLoc, RParenLoc, D,
+ TrailingReturnType),
EndLoc);
return;
}
@@ -3260,9 +3268,6 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
ConsumeToken();
}
- // Leave prototype scope.
- PrototypeScope.Exit();
-
// If we have the closing ')', eat it.
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
SourceLocation EndLoc = RParenLoc;
@@ -3289,8 +3294,19 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
assert(Exceptions.size() == ExceptionRanges.size() &&
"Produced different number of exception types and ranges.");
}
+
+ // Parse trailing-return-type.
+ if (getLang().CPlusPlus0x && Tok.is(tok::arrow)) {
+ TrailingReturnType = ParseTrailingReturnType().get();
+ }
}
+ // FIXME: We should leave the prototype scope before parsing the exception
+ // specification, and then reenter it when parsing the trailing return type.
+
+ // Leave prototype scope.
+ PrototypeScope.Exit();
+
// Remember that we parsed a function type, and remember the attributes.
D.AddTypeInfo(DeclaratorChunk::getFunction(/*proto*/true, IsVariadic,
EllipsisLoc,
@@ -3301,7 +3317,8 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
Exceptions.data(),
ExceptionRanges.data(),
Exceptions.size(),
- LParenLoc, RParenLoc, D),
+ LParenLoc, RParenLoc, D,
+ TrailingReturnType),
EndLoc);
}
OpenPOWER on IntegriCloud