Commit 2153c228 authored by Erik Verbruggen's avatar Erik Verbruggen

[C++11] Fixes semantics for trailing return types.

Now we can parse:
    auto foo()->int;
without getting semantic errors.

Change-Id: Id65c1198c20b2b0c7e8e4eee8ad176d0d66fc0d7
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent 3c635ef1
...@@ -358,12 +358,13 @@ FullySpecifiedType Bind::declarator(DeclaratorAST *ast, const FullySpecifiedType ...@@ -358,12 +358,13 @@ FullySpecifiedType Bind::declarator(DeclaratorAST *ast, const FullySpecifiedType
if (type.isAuto()) if (type.isAuto())
isAuto = true; isAuto = true;
} }
// unsigned equals_token = ast->equals_token; if (!type->isFunctionType()) {
ExpressionTy initializer = this->expression(ast->initializer); ExpressionTy initializer = this->expression(ast->initializer);
if (translationUnit()->cxx0xEnabled() && isAuto) { if (translationUnit()->cxx0xEnabled() && isAuto) {
type = initializer; type = initializer;
type.setAuto(true); type.setAuto(true);
}
} }
std::swap(_declaratorId, declaratorId); std::swap(_declaratorId, declaratorId);
...@@ -3085,6 +3086,8 @@ bool Bind::visit(FunctionDeclaratorAST *ast) ...@@ -3085,6 +3086,8 @@ bool Bind::visit(FunctionDeclaratorAST *ast)
Function *fun = control()->newFunction(0, 0); Function *fun = control()->newFunction(0, 0);
fun->setStartOffset(tokenAt(ast->firstToken()).begin()); fun->setStartOffset(tokenAt(ast->firstToken()).begin());
fun->setEndOffset(tokenAt(ast->lastToken() - 1).end()); fun->setEndOffset(tokenAt(ast->lastToken() - 1).end());
if (ast->trailing_return_type)
_type = this->trailingReturnType(ast->trailing_return_type, _type);
fun->setReturnType(_type); fun->setReturnType(_type);
// unsigned lparen_token = ast->lparen_token; // unsigned lparen_token = ast->lparen_token;
...@@ -3100,7 +3103,6 @@ bool Bind::visit(FunctionDeclaratorAST *ast) ...@@ -3100,7 +3103,6 @@ bool Bind::visit(FunctionDeclaratorAST *ast)
fun->setVolatile(type.isVolatile()); fun->setVolatile(type.isVolatile());
this->exceptionSpecification(ast->exception_specification, type); this->exceptionSpecification(ast->exception_specification, type);
this->trailingReturnType(ast->trailing_return_type, type);
if (ast->as_cpp_initializer != 0) { if (ast->as_cpp_initializer != 0) {
fun->setAmbiguous(true); fun->setAmbiguous(true);
/*ExpressionTy as_cpp_initializer =*/ this->expression(ast->as_cpp_initializer); /*ExpressionTy as_cpp_initializer =*/ this->expression(ast->as_cpp_initializer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment