From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id E3A1F3858413 for ; Wed, 15 Sep 2021 20:44:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E3A1F3858413 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-167-RCgDT83mMmWus-01U2X7QQ-1; Wed, 15 Sep 2021 16:44:01 -0400 X-MC-Unique: RCgDT83mMmWus-01U2X7QQ-1 Received: by mail-qv1-f72.google.com with SMTP id j4-20020ad454c4000000b0037a900dda7aso9986885qvx.14 for ; Wed, 15 Sep 2021 13:44:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=PMdAus2rS+9oCBmLDGQ9zNbWouhmoCrykI2zOieu7AE=; b=c476R4Nr+uqA26d+RksZu54gNG95dwXUFswoAEPXsQQhpicuM3wFsgF+YN2oeABXk4 3+MvjxUjDd3awS55TnLQ56jgf3qOs6HH5HwSQK6YVfl5s0bbrmo/IEOhelbyHl0MlXWN ORa+pH5egdsrASWKPYJj2r85ozTGtbgEmNpoOcUokIjlTIevnqYkzDw3vJRGePwvPOKs BAqrLfcsIaCS9jHEYBw8Ov382orBW0QGAytym6Kh5AteUrBqm4oitpRe32er226NQs40 ugxj/HFAax1E4CNJAauX8GKmpJUQI2XsDxgeMP3maBY3McnOesEhyxej+K/3gOQty+Nd yg3g== X-Gm-Message-State: AOAM533qLYexwWXE0MOF5Sqoxr5vWZiBLTT6Ztr4V0om2WjvE8rrddZ6 7N1gj4Dt8hC2zYDPGI1L7fCRaPCYSIS7h5nPrfaQKy1EUCDrv6gemnIU4dOkAB3FZ9vm6KViYTj lbJVkf3GUJCU8dpQ3cQ== X-Received: by 2002:a05:620a:2492:: with SMTP id i18mr1858314qkn.57.1631738640155; Wed, 15 Sep 2021 13:44:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO7Z5zUYcs4l3/YfAM/dvEXZK22U/+4ewV1P8TbQem4QeTLV9xYx6aidZEdJYtsc9/2SiEVQ== X-Received: by 2002:a05:620a:2492:: with SMTP id i18mr1858284qkn.57.1631738639790; Wed, 15 Sep 2021 13:43:59 -0700 (PDT) Received: from [192.168.1.149] (130-44-159-43.s11817.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id o23sm720488qtq.7.2021.09.15.13.43.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Sep 2021 13:43:59 -0700 (PDT) Message-ID: <63d2c5da-2089-2a41-9427-9c0d7d786272@redhat.com> Date: Wed, 15 Sep 2021 16:43:58 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH] c++: fix wrong fixit hints for misspelled typedef [PR77565] To: Michel Morin , David Malcolm Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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: Wed, 15 Sep 2021 20:44:04 -0000 On 9/14/21 04:29, Michel Morin via Gcc-patches wrote: > 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 ;) That is strange. Let's add all the rest of them as well. >> 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 >> >> >