From: Ted Kremenek Date: Wed, 23 Dec 2009 04:00:48 +0000 (+0000) Subject: Fix CXXConstructExpr::getSourceRange() to not include the source ranges of CXXDefault... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e383768f7f5d45ca4af0b1c11cbf072de18bce98;p=clang Fix CXXConstructExpr::getSourceRange() to not include the source ranges of CXXDefaultArgExprs when computing its range (since these expressions have no source range, and using them will make the encompassing range invalid). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91984 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 4b540d9c54..88e667a2c2 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -561,13 +561,7 @@ public: Args[Arg] = ArgExpr; } - virtual SourceRange getSourceRange() const { - // FIXME: Should we know where the parentheses are, if there are any? - if (NumArgs == 0) - return SourceRange(Loc); - - return SourceRange(Loc, Args[NumArgs - 1]->getLocEnd()); - } + virtual SourceRange getSourceRange() const; static bool classof(const Stmt *T) { return T->getStmtClass() == CXXConstructExprClass || diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 9c14f741fd..5444a7748c 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -282,6 +282,18 @@ bool UnaryTypeTraitExpr::EvaluateTrait(ASTContext& C) const { } } +SourceRange CXXConstructExpr::getSourceRange() const { + // FIXME: Should we know where the parentheses are, if there are any? + for (std::reverse_iterator I(&Args[NumArgs]), E(&Args[0]); I!=E;++I) { + // Ignore CXXDefaultExprs when computing the range, as they don't + // have a range. + if (!isa(*I)) + return SourceRange(Loc, (*I)->getLocEnd()); + } + + return SourceRange(Loc); +} + SourceRange CXXOperatorCallExpr::getSourceRange() const { OverloadedOperatorKind Kind = getOperator(); if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {