From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x935.google.com (mail-ua1-x935.google.com [IPv6:2607:f8b0:4864:20::935]) by sourceware.org (Postfix) with ESMTPS id 6CE7F3858402 for ; Tue, 14 Sep 2021 08:30:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6CE7F3858402 Received: by mail-ua1-x935.google.com with SMTP id r8so8027750uap.0 for ; Tue, 14 Sep 2021 01:30:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IermR572V8H/DG6qbGvbpdRBTrAKxHwC4cqr0kcOzww=; b=5UBg22xifOTyFF6HVlqIUAufwg7cGDpJoMwGWbvxpR0HptOvckww28NP5/ZQD7pJWN CAUuDnQVMtsn+FLi9sL3vq+R4jsqlhzX5xedeJAqhIGOdh6/JIlV9mwXlLhx0UCxJgo4 FzH5x3Qzva0l+qzGBt9juR619mLt6We8HW1qBhdpeZ9y2lvsXUZOAygmm3RJnVKsj+M6 SwzRM5QLyFGGCLpB0ekEaR/9giyC72wBixkggBA/qcJVy/BQ4LySCkD2DzNr7OWC03Vj Si1WqYysxwRP8rIuwomHp4+UcIlgu7ejQ2xsFVCRIUPbR0VaxTqngoQ5oz7fE42ojEu3 SOEQ== X-Gm-Message-State: AOAM531ipffFnifW8Kw17wAGTwsnL8PNnDWPXMPxRqi1QtLmbTcRZqyi WLDabYM1gWRhZr8BhY7WkUFDKM9OrO+w0fZ+xMo= X-Google-Smtp-Source: ABdhPJyZ48qYtN0SPmP5cDd9GjcxQ4CjutOf5f3Pc4k3ZJNGP0C5fJ9teEhxuoMqoa329uGoO4bExIpd4ULZny+9jzM= X-Received: by 2002:ab0:3c92:: with SMTP id a18mr3406095uax.23.1631608208963; Tue, 14 Sep 2021 01:30:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Michel Morin Date: Tue, 14 Sep 2021 17:29:58 +0900 Message-ID: Subject: Re: [PATCH] c++: fix wrong fixit hints for misspelled typedef [PR77565] To: David Malcolm Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Sep 2021 08:30:13 -0000 On Tue, Sep 14, 2021 at 7:14 AM David Malcolm wrote: > > On Tue, 2021-09-14 at 03:35 +0900, Michel Morin via Gcc-patches wrote: > > Hi, > > > > PR77565 reports that, with the code `typdef int Int;`, GCC emits > > "did you mean 'typeof'?" instead of "did you mean 'typedef'?". > > > > This happens because the typo corrector determines that `typeof` is a > > candidate for suggestion (through > > `cp_keyword_starts_decl_specifier_p`), > > but `typedef` is not. > > > > This patch fixes the issue by adding `typedef` as a candidate. The > > patch > > additionally adds the `inline` specifier and cv-specifiers as a > > candidate. > > Here is a patch (tests `make check-gcc` pass on darwin): > > Thanks for this patch (and for reporting the bug in the first place). > > I notice that, as well as being used for fix-it hints by > lookup_name_fuzzy (indirectly via suggest_rid_p), > cp_keyword_starts_decl_specifier_p is also used by > cp_lexer_next_token_is_decl_specifier_keyword, which is used by > cp_parser_lambda_declarator_opt and cp_parser_constructor_declarator_p. Ah, you're right! Thank you for pointing this out. I failed to grep those functions somehow. One thing that confuses me is that cp_keyword_starts_decl_specifier_p misses many keywords that can start decl-specifiers (e.g. typedef/inline/cv-qual and friend/explicit/virtual). So let's wait C++ frontend maintainers ;) Regards, Michel > So I'm not sure if this fix is exactly correct - hopefully one of the > C++ frontend maintainers can chime in. If > cp_keyword_starts_decl_specifier_p isn't quite the right place for > this, the fix could probably go in suggest_rid_p instead, which *is* > specific to spelling corrections. > > Hope this is constructive; thanks again for the patch > Dave > > > > > > > ============================================ > > c++: add typo corrections for typedef/inline/cv-qual [PR77565] > > > > PR c++/77565 > > > > gcc/cp/ChangeLog: > > > > * parser.c (cp_keyword_starts_decl_specifier_p): Handle > > typedef/inline specifiers and cv-qualifiers. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/spellcheck-typenames.C: Add tests for decl-specs. > > > > --- a/gcc/cp/parser.c > > +++ b/gcc/cp/parser.c > > @@ -1051,6 +1051,12 @@ cp_keyword_starts_decl_specifier_p (enum rid > > keyword) > > case RID_FLOAT: > > case RID_DOUBLE: > > case RID_VOID: > > + /* CV qualifiers. */ > > + case RID_CONST: > > + case RID_VOLATILE: > > + /* typedef/inline specifiers. */ > > + case RID_TYPEDEF: > > + case RID_INLINE: > > /* GNU extensions. */ > > case RID_ATTRIBUTE: > > case RID_TYPEOF: > > --- a/gcc/testsuite/g++.dg/spellcheck-typenames.C > > +++ b/gcc/testsuite/g++.dg/spellcheck-typenames.C > > @@ -76,3 +76,38 @@ singed char ch; // { dg-error "1: 'singed' does > > not > > name a type; did you mean 's > > ^~~~~~ > > signed > > { dg-end-multiline-output "" } */ > > + > > +typdef int my_int; // { dg-error "1: 'typdef' does not name a type; > > did you mean 'typedef'?" } > > +/* { dg-begin-multiline-output "" } > > + typdef int my_int; > > + ^~~~~~ > > + typedef > > + { dg-end-multiline-output "" } */ > > + > > +inlien int inline_func(); // { dg-error "1: 'inlien' does not name a > > type; did you mean 'inline'?" } > > +/* { dg-begin-multiline-output "" } > > + inlien int inline_func(); > > + ^~~~~~ > > + inline > > + { dg-end-multiline-output "" } */ > > + > > +coonst int ci = 0; // { dg-error "1: 'coonst' does not name a type; > > did you mean 'const'?" } > > +/* { dg-begin-multiline-output "" } > > + coonst int ci = 0; > > + ^~~~~~ > > + const > > + { dg-end-multiline-output "" } */ > > + > > +voltil int vi; // { dg-error "1: 'voltil' does not name a type; did > > you mean 'volatile'?" } > > +/* { dg-begin-multiline-output "" } > > + voltil int vi; > > + ^~~~~~ > > + volatile > > + { dg-end-multiline-output "" } */ > > + > > +statik int si; // { dg-error "1: 'statik' does not name a type; did > > you mean 'static'?" } > > +/* { dg-begin-multiline-output "" } > > + statik int si; > > + ^~~~~~ > > + static > > + { dg-end-multiline-output "" } */ > > ============================================ > > > > -- > > Regards, > > Michel > >