]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Don't suggest cdtor or conversion op identifiers in spelling hints [PR104806]
authorJakub Jelinek <jakub@redhat.com>
Tue, 8 Mar 2022 20:41:21 +0000 (21:41 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 11 May 2022 06:17:57 +0000 (08:17 +0200)
On the following testcase, we emit "did you mean '__dt '?" in the error
message.  "__dt " shows there because it is dtor_identifier, but we
shouldn't suggest those to the user, they are purely internal and can't
be really typed by the user because of the final space in it.

2022-03-08  Jakub Jelinek  <jakub@redhat.com>

PR c++/104806
* search.c (lookup_field_fuzzy_info::fuzzy_lookup_field): Ignore
identifiers with space at the end.

* g++.dg/spellcheck-pr104806.C: New test.

(cherry picked from commit e480c3c06d20874fd7504bfdcca0b829f8000389)

gcc/cp/search.c
gcc/testsuite/g++.dg/spellcheck-pr104806.C [new file with mode: 0644]

index 4c3fffda717c21db0b6c6bae32330b2cd9238ddf..39b8680d642c770eae5ec892d53ad79854068794 100644 (file)
@@ -1249,6 +1249,13 @@ lookup_field_fuzzy_info::fuzzy_lookup_field (tree type)
       if (is_lambda_ignored_entity (field))
        continue;
 
+      /* Ignore special identifiers with space at the end like cdtor or
+        conversion op identifiers.  */
+      if (TREE_CODE (DECL_NAME (field)) == IDENTIFIER_NODE)
+       if (unsigned int len = IDENTIFIER_LENGTH (DECL_NAME (field)))
+         if (IDENTIFIER_POINTER (DECL_NAME (field))[len - 1] == ' ')
+           continue;
+
       m_candidates.safe_push (DECL_NAME (field));
     }
 }
diff --git a/gcc/testsuite/g++.dg/spellcheck-pr104806.C b/gcc/testsuite/g++.dg/spellcheck-pr104806.C
new file mode 100644 (file)
index 0000000..559e601
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/104806
+
+struct S {};
+int main() { S s; s.__d; }     // { dg-bogus "'struct S' has no member named '__d'; did you mean '__\[a-z]* '" }
+                               // { dg-error "'struct S' has no member named '__d'" "" { target *-*-* } .-1 }