[cfe-commits] r70390 - in /cfe/trunk: include/clang/AST/Expr.h lib/Sema/SemaExpr.cpp test/SemaCXX/member-location.cpp
Eli Friedman
eli.friedman at gmail.com
Wed Apr 29 10:56:47 PDT 2009
Author: efriedma
Date: Wed Apr 29 12:56:47 2009
New Revision: 70390
URL: http://llvm.org/viewvc/llvm-project?rev=70390&view=rev
Log:
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.
Added:
cfe/trunk/test/SemaCXX/member-location.cpp
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=70390&r1=70389&r2=70390&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Apr 29 12:56:47 2009
@@ -1060,7 +1060,12 @@
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; }
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=70390&r1=70389&r2=70390&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Apr 29 12:56:47 2009
@@ -878,7 +878,7 @@
Expr *This = new (Context) CXXThisExpr(SourceLocation(),
MD->getThisType(Context));
return Owned(new (Context) MemberExpr(This, true, D,
- SourceLocation(), MemberType));
+ Loc, MemberType));
}
}
}
Added: cfe/trunk/test/SemaCXX/member-location.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-location.cpp?rev=70390&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/member-location.cpp (added)
+++ cfe/trunk/test/SemaCXX/member-location.cpp Wed Apr 29 12:56:47 2009
@@ -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}}
+
More information about the cfe-commits
mailing list