]> granicus.if.org Git - clang/commitdiff
Fix a QoI bug reported by a user.
authorMatt Beaumont-Gay <matthewbg@google.com>
Sat, 21 Apr 2012 01:12:48 +0000 (01:12 +0000)
committerMatt Beaumont-Gay <matthewbg@google.com>
Sat, 21 Apr 2012 01:12:48 +0000 (01:12 +0000)
Set the source location for the "member reference base type ... is not a
structure or union" diag to point at the operator rather than the member name.
If we're giving this diagnostic because of a typo'd '.' in place of a ';' at
the end of a line, the caret previously pointed at the identifier on the
following line, which isn't as helpful as it could be. Pointing the caret at
the '.' makes it more obvious what the problem is.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155267 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprMember.cpp
test/SemaCXX/member-expr.cpp

index 6c84caa3f37121c9139520ef207745e74a99648c..bebb498b64063e5f2db71fbfc5f9fcee734f0d5d 100644 (file)
@@ -436,7 +436,7 @@ Sema::ActOnDependentMemberExpr(Expr *BaseExpr, QualType BaseType,
     if (PT && (!getLangOpts().ObjC1 ||
                PT->getPointeeType()->isRecordType())) {
       assert(BaseExpr && "cannot happen with implicit member accesses");
-      Diag(NameInfo.getLoc(), diag::err_typecheck_member_reference_struct_union)
+      Diag(OpLoc, diag::err_typecheck_member_reference_struct_union)
         << BaseType << BaseExpr->getSourceRange();
       return ExprError();
     }
@@ -1418,7 +1418,7 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
                             ObjCImpDecl, HasTemplateArgs);
   }
 
-  Diag(MemberLoc, diag::err_typecheck_member_reference_struct_union)
+  Diag(OpLoc, diag::err_typecheck_member_reference_struct_union)
     << BaseType << BaseExpr.get()->getSourceRange();
 
   return ExprError();
index dbddd1c2e3e1749c6fa6f95959e2fa29db572c5f..763f9c754c1e80f88a9741a8727c1925cc02fdb9 100644 (file)
@@ -157,3 +157,13 @@ namespace FuncInMemberExpr {
   Vec fun3(int x = 0);
   int test3() { return fun3.size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
 }
+
+namespace DotForSemiTypo {
+void f(int i) {
+  // If the programmer typo'd '.' for ';', make sure we point at the '.' rather
+  // than the "field name" (whatever the first token on the next line happens to
+  // be).
+  int j = i. // expected-error {{member reference base type 'int' is not a structure or union}}
+  j = 0;
+}
+}