From: Abramo Bagnara Date: Mon, 15 Oct 2012 21:05:46 +0000 (+0000) Subject: Fixed FunctionTypeLoc range for trailing return type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac8ea058febf6041871386d135ac2b955ab5d83a;p=clang Fixed FunctionTypeLoc range for trailing return type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165974 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index de9d22ad9d..c9c084ab83 100644 --- a/lib/AST/TypeLoc.cpp +++ b/lib/AST/TypeLoc.cpp @@ -98,64 +98,27 @@ void TypeLoc::initializeImpl(ASTContext &Context, TypeLoc TL, SourceLocation TypeLoc::getBeginLoc() const { TypeLoc Cur = *this; - SourceLocation SavedParenLoc; while (true) { switch (Cur.getTypeLocClass()) { - // FIXME: Currently QualifiedTypeLoc does not have a source range - // case Qualified: - case Elaborated: - case DependentName: - case DependentTemplateSpecialization: - break; - - case Paren: - // Save local source begin, if still unset. - if (SavedParenLoc.isInvalid()) - SavedParenLoc = Cur.getLocalSourceRange().getBegin(); - Cur = Cur.getNextTypeLoc(); - assert(!Cur.isNull()); - continue; - break; - - case Pointer: - case BlockPointer: - case MemberPointer: - case ObjCObjectPointer: - case LValueReference: - case RValueReference: - case ConstantArray: - case DependentSizedArray: - case IncompleteArray: - case VariableArray: - case FunctionNoProto: - // Discard previously saved paren loc, if any. - SavedParenLoc = SourceLocation(); - Cur = Cur.getNextTypeLoc(); - assert(!Cur.isNull()); - continue; - break; - case FunctionProto: - // Discard previously saved paren loc, if any. - SavedParenLoc = SourceLocation(); if (cast(&Cur)->getTypePtr()->hasTrailingReturn()) return Cur.getLocalSourceRange().getBegin(); Cur = Cur.getNextTypeLoc(); assert(!Cur.isNull()); continue; - break; + + // FIXME: Currently QualifiedTypeLoc does not have a source range + // case Qualified: + case Elaborated: + return Cur.getLocalSourceRange().getBegin(); default: - TypeLoc Next = Cur.getNextTypeLoc(); - if (Next.isNull()) break; - Cur = Next; + if (Cur.getNextTypeLoc().isNull()) + return Cur.getLocalSourceRange().getBegin(); + Cur = Cur.getNextTypeLoc(); continue; - } - break; - } - return SavedParenLoc.isValid() - ? SavedParenLoc - : Cur.getLocalSourceRange().getBegin(); + } // switch + } // while } SourceLocation TypeLoc::getEndLoc() const { diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 3ef4f38ad0..3e4d92abe8 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -4582,7 +4582,10 @@ void Parser::ParseFunctionDeclarator(Declarator &D, Actions.ActOnStartFunctionDeclarator(); - SourceLocation StartLoc, EndLoc; + /* LocalEndLoc is the end location for the local FunctionTypeLoc. + EndLoc is the end location for the function declarator. + They differ for trailing return types. */ + SourceLocation StartLoc, LocalEndLoc, EndLoc; SourceLocation LParenLoc, RParenLoc; LParenLoc = Tracker.getOpenLocation(); StartLoc = LParenLoc; @@ -4595,6 +4598,7 @@ void Parser::ParseFunctionDeclarator(Declarator &D, Tracker.consumeClose(); RParenLoc = Tracker.getCloseLocation(); + LocalEndLoc = RParenLoc; EndLoc = RParenLoc; } else { if (Tok.isNot(tok::r_paren)) @@ -4607,6 +4611,7 @@ void Parser::ParseFunctionDeclarator(Declarator &D, // If we have the closing ')', eat it. Tracker.consumeClose(); RParenLoc = Tracker.getCloseLocation(); + LocalEndLoc = RParenLoc; EndLoc = RParenLoc; if (getLangOpts().CPlusPlus) { @@ -4663,13 +4668,15 @@ void Parser::ParseFunctionDeclarator(Declarator &D, MaybeParseCXX0XAttributes(FnAttrs); // Parse trailing-return-type[opt]. + LocalEndLoc = EndLoc; if (getLangOpts().CPlusPlus0x && Tok.is(tok::arrow)) { Diag(Tok, diag::warn_cxx98_compat_trailing_return_type); if (D.getDeclSpec().getTypeSpecType() == TST_auto) StartLoc = D.getDeclSpec().getTypeSpecTypeLoc(); - EndLoc = Tok.getLocation(); + LocalEndLoc = Tok.getLocation(); SourceRange Range; TrailingReturnType = ParseTrailingReturnType(Range); + EndLoc = Range.getEnd(); } } } @@ -4691,7 +4698,7 @@ void Parser::ParseFunctionDeclarator(Declarator &D, DynamicExceptions.size(), NoexceptExpr.isUsable() ? NoexceptExpr.get() : 0, - StartLoc, EndLoc, D, + StartLoc, LocalEndLoc, D, TrailingReturnType), FnAttrs, EndLoc);