[cfe-commits] r155267 - in /cfe/trunk: lib/Sema/SemaExprMember.cpp test/SemaCXX/member-expr.cpp

Matt Beaumont-Gay matthewbg at google.com
Fri Apr 20 18:12:48 PDT 2012


Author: matthewbg
Date: Fri Apr 20 20:12:48 2012
New Revision: 155267

URL: http://llvm.org/viewvc/llvm-project?rev=155267&view=rev
Log:
Fix a QoI bug reported by a user.

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.

Modified:
    cfe/trunk/lib/Sema/SemaExprMember.cpp
    cfe/trunk/test/SemaCXX/member-expr.cpp

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=155267&r1=155266&r2=155267&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Fri Apr 20 20:12:48 2012
@@ -436,7 +436,7 @@
     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 @@
                             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();

Modified: cfe/trunk/test/SemaCXX/member-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-expr.cpp?rev=155267&r1=155266&r2=155267&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-expr.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-expr.cpp Fri Apr 20 20:12:48 2012
@@ -157,3 +157,13 @@
   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;
+}
+}





More information about the cfe-commits mailing list