]> granicus.if.org Git - clang/commitdiff
PR4103: improve source location information for members of the current
authorEli Friedman <eli.friedman@gmail.com>
Wed, 29 Apr 2009 17:56:47 +0000 (17:56 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 29 Apr 2009 17:56:47 +0000 (17:56 +0000)
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

include/clang/AST/Expr.h
lib/Sema/SemaExpr.cpp
test/SemaCXX/member-location.cpp [new file with mode: 0644]

index 1366450b52743b7a25df745e95ea5243169f56d6..8ba69fcc09e652476499459a9a0ad14759155f64 100644 (file)
@@ -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; }
index c4360a94a72521346a45897d6fb1972a39436715..dcc0311f6042e8760c36da7de24d5678d8f68a8c 100644 (file)
@@ -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 (file)
index 0000000..cb53ae1
--- /dev/null
@@ -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}}
+