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; }
Expr *This = new (Context) CXXThisExpr(SourceLocation(),
MD->getThisType(Context));
return Owned(new (Context) MemberExpr(This, true, D,
- SourceLocation(), MemberType));
+ Loc, MemberType));
}
}
}
--- /dev/null
+// 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}}
+