diff options
-rw-r--r-- | include/clang/AST/Expr.h | 7 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 2 | ||||
-rw-r--r-- | test/SemaCXX/member-location.cpp | 5 |
3 files changed, 12 insertions, 2 deletions
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}} + |