Fixed FunctionTypeLoc range for trailing return type.
llvm-svn: 165974
This commit is contained in:
parent
bbd469bef3
commit
2fc03caee8
|
@ -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<FunctionProtoTypeLoc>(&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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue