]> granicus.if.org Git - clang/commitdiff
Give a more informative error message when the dot or arrow operator is used
authorRichard Trieu <rtrieu@google.com>
Sat, 26 Jan 2013 02:31:38 +0000 (02:31 +0000)
committerRichard Trieu <rtrieu@google.com>
Sat, 26 Jan 2013 02:31:38 +0000 (02:31 +0000)
on a type.  Currently, it gives a generic "expected unqualified-id" error.
The new error message is "cannot use (dot|arrow) operator on a type".

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

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDecl.cpp
test/Parser/cxx-decl.cpp

index 055e79c258d3a0922bfae06524cfc3ca2d72bfca..474428efa3597b811faadee8e48e29a66d3a02c4 100644 (file)
@@ -422,6 +422,8 @@ def err_declaration_does_not_declare_param : Error<
 def err_no_matching_param : Error<"parameter named %0 is missing">;
 
 /// C++ parser diagnostics
+def err_invalid_operator_on_type : Error<
+  "cannot use %select{dot|arrow}0 operator on a type">;
 def err_expected_unqualified_id : Error<
   "expected %select{identifier|unqualified-id}0">;
 def err_func_def_no_params : Error<
index cfe5d1b16ab447709c2ad0682b404a02da8921a7..6acb0b2eb8f05b8759cf122c433bfdeda676dca1 100644 (file)
@@ -4498,9 +4498,12 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
     if (D.getContext() == Declarator::MemberContext)
       Diag(Tok, diag::err_expected_member_name_or_semi)
         << D.getDeclSpec().getSourceRange();
-    else if (getLangOpts().CPlusPlus)
-      Diag(Tok, diag::err_expected_unqualified_id) << getLangOpts().CPlusPlus;
-    else
+    else if (getLangOpts().CPlusPlus) {
+      if (Tok.is(tok::period) || Tok.is(tok::arrow))
+        Diag(Tok, diag::err_invalid_operator_on_type) << Tok.is(tok::arrow);
+      else
+        Diag(Tok, diag::err_expected_unqualified_id) << getLangOpts().CPlusPlus;
+    } else
       Diag(Tok, diag::err_expected_ident_lparen);
     D.SetIdentifier(0, Tok.getLocation());
     D.setInvalidType(true);
index ee292fdae0f7da85846edb5f9655e2268c9f2814..71fd7aae18d8b47246d0b7c49dd23fa3cb12d8a2 100644 (file)
@@ -162,6 +162,24 @@ bitand r2 = v;
 
 }
 
+struct DIE {
+  void foo() {}
+};
+
+void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) {
+  DIE.foo();  // expected-error {{cannot use dot operator on a type}}
+  die.foo();
+
+  DIE->foo();  // expected-error {{cannot use arrow operator on a type}}
+  Die->foo();
+
+  int.foo();  // expected-error {{cannot use dot operator on a type}}
+  INT.foo();
+
+  float->foo();  // expected-error {{cannot use arrow operator on a type}}
+  FLOAT->foo();
+}
+
 // PR8380
 extern ""      // expected-error {{unknown linkage language}}
 test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \