public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10692] c++: Don't suggest cdtor or conversion op identifiers in spelling hints [PR104806]
Date: Tue, 10 May 2022 08:24:59 +0000 (GMT)	[thread overview]
Message-ID: <20220510082459.A15FD3836010@sourceware.org> (raw)

https://gcc.gnu.org/g:da83eb387b2e0e4dfab73b735beac87ed269c866

commit r10-10692-gda83eb387b2e0e4dfab73b735beac87ed269c866
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Mar 8 21:41:21 2022 +0100

    c++: Don't suggest cdtor or conversion op identifiers in spelling hints [PR104806]
    
    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)

Diff:
---
 gcc/cp/search.c                            | 7 +++++++
 gcc/testsuite/g++.dg/spellcheck-pr104806.C | 5 +++++
 2 files changed, 12 insertions(+)

diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 6eada2d3788..dd013f9d668 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -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
index 00000000000..559e6019163
--- /dev/null
+++ b/gcc/testsuite/g++.dg/spellcheck-pr104806.C
@@ -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 }


                 reply	other threads:[~2022-05-10  8:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220510082459.A15FD3836010@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).