]> granicus.if.org Git - clang/commitdiff
Provide a better diagnostic and a fixit for a '.' or '->' before the left paren
authorKaelyn Uhrain <rikka@google.com>
Fri, 12 Jul 2013 21:43:02 +0000 (21:43 +0000)
committerKaelyn Uhrain <rikka@google.com>
Fri, 12 Jul 2013 21:43:02 +0000 (21:43 +0000)
of a function call.

This fixes PR5898 and means we now have a better diagnostic here than GCC.

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

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseExpr.cpp
test/FixIt/fixit.cpp

index d5982e9825d9f678e47aeed3d509a45143e5722e..012d13d4cdd0885018e7e6f8369d911cefc6a15e 100644 (file)
@@ -498,6 +498,9 @@ def err_misplaced_ellipsis_in_declaration : Error<
 def ext_abstract_pack_declarator_parens : ExtWarn<
   "ISO C++11 requires a parenthesized pack declaration to have a name">,
   InGroup<DiagGroup<"anonymous-pack-parens">>;
+def err_function_is_not_record : Error<
+  "unexpected '%select{.|->}0' in function call; perhaps remove the "
+  "'%select{.|->}0'?">;
 
 // C++ derived classes
 def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">;
index 9521ffbc0e3f745ffaa9bfde8f6d1331fee0979d..f9c7c4e3b45d59570b0af3aa460a334c254ae06a 100644 (file)
@@ -1457,7 +1457,19 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
       ParsedType ObjectType;
       bool MayBePseudoDestructor = false;
       if (getLangOpts().CPlusPlus && !LHS.isInvalid()) {
-        LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), LHS.take(),
+        Expr *Base = LHS.take();
+        const Type* BaseType = Base->getType().getTypePtrOrNull();
+        if (BaseType && Tok.is(tok::l_paren) &&
+            (BaseType->isFunctionType() ||
+             BaseType->getAsPlaceholderType()->getKind() ==
+                 BuiltinType::BoundMember)) {
+          Diag(OpLoc, diag::err_function_is_not_record)
+            << (OpKind == tok::arrow) << Base->getSourceRange()
+            << FixItHint::CreateRemoval(OpLoc);
+          return ParsePostfixExpressionSuffix(Base);
+        }
+
+        LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base,
                                                    OpLoc, OpKind, ObjectType,
                                                    MayBePseudoDestructor);
         if (LHS.isInvalid())
index a858a82e7f92036c41e26e84b3bcc4c3b0d2f06e..400c227128a8f596e017d8682b74d054f3e217f2 100644 (file)
@@ -324,3 +324,17 @@ namespace PR15045 {
     return c->a;  // expected-error {{member reference type 'PR15045::Cl0' is not a pointer; maybe you meant to use '.'?}}
   }
 }
+
+namespace PR5898 {
+  class A {
+  public:
+    const char *str();
+  };
+  const char* foo(A &x)
+  {
+    return x.str.();  // expected-error {{unexpected '.' in function call; perhaps remove the '.'?}}
+  }
+  bool bar(A x, const char *y) {
+    return foo->(x) == y;  // expected-error {{unexpected '->' in function call; perhaps remove the '->'?}}
+  }
+}