aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-04-29 17:56:47 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-04-29 17:56:47 +0000
commit72527137c521ad9330ecb81ccd841159719dc8cd (patch)
tree8fc5df682ca72e330cdfe8ee9637d27ffba9a531
parent7dc813462dd9fd3f6f4296f896a12de14264fef8 (diff)
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
-rw-r--r--include/clang/AST/Expr.h7
-rw-r--r--lib/Sema/SemaExpr.cpp2
-rw-r--r--test/SemaCXX/member-location.cpp5
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}}
+