From patchwork Mon Sep 13 18:35:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Morin X-Patchwork-Id: 44960 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3475E3858434 for ; Mon, 13 Sep 2021 18:36:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3475E3858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631558192; bh=1e2t+NDbw0Dnr/fkScy/7Skw+cYguU9weHrX6OLu28U=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Csy46LvB8+dbmKWwvmc9LklnB7iasu5Zet1AW65BurMYMV/jnmYwvfSEXg3Qfzg1q D+7Akcu7dw8w7QCV8ey4ksMv97JEsduE7MxBsLj4eTbGN7QCH9Mz5gaNpITvgEkKPk lPZD/NLNQMOLziahnvrDLsoyMMh/BksTS7omN+x0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 C6F41385842B for ; Mon, 13 Sep 2021 18:35:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C6F41385842B Received: by mail-ua1-x935.google.com with SMTP id s4so6854267uar.5 for ; Mon, 13 Sep 2021 11:35:29 -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:from:date:message-id:subject:to; bh=1e2t+NDbw0Dnr/fkScy/7Skw+cYguU9weHrX6OLu28U=; b=wlTrIYBxsramWJm+8lzTk8q59q8H3J0UrSC1UKiILwDQ6M8C14Db+/ku2otNoBFsBg jBAitXfok6Ya6w8Piict8GC7HoGDVcOjsTqsWLODVmtnErpXfTPt28WxnRmiRGo6Ginl FnBhFd800OWFZeZEnfPuG1E/eN9Raj5sQkbvsHfabIqvyaqRxxSaQ+qdjx2GPHrQLBfw 0pzsyD8qJ8tLpHIkIQzR9X0HfshkoBQEjfr4YjhkZKab62Ongrt1epqXM7u/jJqoQLZb 5eHVl9gHi6b62L8VGa+VqUiG8OUxfx10KO38pFD44fs+FIYQLLhhDUBJPZKGGwIaVIZV WUGA== X-Gm-Message-State: AOAM533X6eNrQIui/7HVgEOPeZ5pB1pkeJJGga6Ok055xzetkRrlJXlj MhztrSVhIYHrKxn2wAKdzaeYhoy4YMVCPIt2oVcDP7mMhT5h5w== X-Google-Smtp-Source: ABdhPJwHdJxHxfOG7jPGzy1KH5esLQs/9h5LwpQafVxfHymLoDouahbaXlYUUte5issS0KXWTFymaeNjgXX7Rzp563Y= X-Received: by 2002:a9f:238b:: with SMTP id 11mr1155663uao.91.1631558129063; Mon, 13 Sep 2021 11:35:29 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 14 Sep 2021 03:35:18 +0900 Message-ID: Subject: [PATCH] c++: fix wrong fixit hints for misspelled typedef [PR77565] To: gcc-patches@gcc.gnu.org X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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-Patchwork-Original-From: Michel Morin via Gcc-patches From: Michel Morin Reply-To: Michel Morin Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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): ============================================ 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. you mean 'static'?" } +/* { dg-begin-multiline-output "" } + statik int si; + ^~~~~~ + static + { dg-end-multiline-output "" } */ ============================================ --- Regards, Michel diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index f9c2c8ac3a7..5295911eb82 100644 --- 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: diff --git a/gcc/testsuite/g++.dg/spellcheck-typenames.C b/gcc/testsuite/g++.dg/spellcheck-typenames.C index ff53ecc6303..75f80480e16 100644 --- 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 "" } */ --- 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