From: Eli Friedman Date: Wed, 29 Apr 2009 17:56:47 +0000 (+0000) Subject: PR4103: improve source location information for members of the current X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72527137c521ad9330ecb81ccd841159719dc8cd;p=clang PR4103: improve source location information for members of the current class. This isn't perfect, but it's a big improvement over not having any location information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70390 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 1366450b52..8ba69fcc09 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1060,7 +1060,12 @@ public: void setMemberLoc(SourceLocation L) { MemberLoc = L; } virtual SourceRange getSourceRange() const { - return SourceRange(getBase()->getLocStart(), MemberLoc); + // If we have an implicit base (like a C++ implicit this), + // make sure not to return its location + SourceLocation BaseLoc = getBase()->getLocStart(); + if (BaseLoc.isInvalid()) + return SourceRange(MemberLoc, MemberLoc); + return SourceRange(BaseLoc, MemberLoc); } virtual SourceLocation getExprLoc() const { return MemberLoc; } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c4360a94a7..dcc0311f60 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -878,7 +878,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, Expr *This = new (Context) CXXThisExpr(SourceLocation(), MD->getThisType(Context)); return Owned(new (Context) MemberExpr(This, true, D, - SourceLocation(), MemberType)); + Loc, MemberType)); } } } diff --git a/test/SemaCXX/member-location.cpp b/test/SemaCXX/member-location.cpp new file mode 100644 index 0000000000..cb53ae1512 --- /dev/null +++ b/test/SemaCXX/member-location.cpp @@ -0,0 +1,5 @@ +// RUN: clang-cc -fsyntax-only -verify %s +// PR4103: Make sure we have a location for the error +class A { float a(int *); int b(); }; +int A::b() { return a(a((int*)0)); } // expected-error {{incompatible type}} +