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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 322E8385771A for ; Fri, 16 Jun 2023 01:01:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 322E8385771A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686877302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xZUqttf9R4FmIDbUc+CndK5hiVX1ChKLNw+iXjUHfZI=; b=PH8yL87rD8lBLqCZAlWJkv121dh7qPZFRK6gY3b5Ed6IQ4yZ+e3BZNuZTe5sRx5tigUkAK yWd/oHN3iWePDPPeIoUSYs7TGe8PE9OOA1pd1NLFvBDCBJ2xldL7wI2wZx4lr7R3UzePJM Yi9AX3XLCsvhfB5O5BcDiDkdnx56r40= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-652-mOGDh8mlP-KhgJA3IBcDgg-1; Thu, 15 Jun 2023 21:01:39 -0400 X-MC-Unique: mOGDh8mlP-KhgJA3IBcDgg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B621101A58E for ; Fri, 16 Jun 2023 01:01:39 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.32.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65C5C48FB01; Fri, 16 Jun 2023 01:01:39 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] c: add name hints to c_parser_declspecs [PR107583] Date: Thu, 15 Jun 2023 21:01:38 -0400 Message-Id: <20230616010138.1047991-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: PR c/107583 notes that we weren't issuing a hint for struct foo { time_t mytime; /* missing include should trigger fixit */ }; in the C frontend. The root cause is that one of the "unknown type name" diagnostics was missing logic to emit hints, which this patch fixes. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-1876-g57446d1bc9757e. gcc/c/ChangeLog: PR c/107583 * c-parser.cc (c_parser_declspecs): Add hints to "unknown type name" error. gcc/testsuite/ChangeLog: PR c/107583 * c-c++-common/spellcheck-pr107583.c: New test. --- gcc/c/c-parser.cc | 14 +++++++++++++- gcc/testsuite/c-c++-common/spellcheck-pr107583.c | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/spellcheck-pr107583.c diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 5baa501dbee..f8b14e4c688 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -3182,7 +3182,19 @@ c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, attrs_ok = true; if (kind == C_ID_ID) { - error_at (loc, "unknown type name %qE", value); + auto_diagnostic_group d; + name_hint hint = lookup_name_fuzzy (value, FUZZY_LOOKUP_TYPENAME, + loc); + if (const char *suggestion = hint.suggestion ()) + { + gcc_rich_location richloc (loc); + richloc.add_fixit_replace (suggestion); + error_at (&richloc, + "unknown type name %qE; did you mean %qs?", + value, suggestion); + } + else + error_at (loc, "unknown type name %qE", value); t.kind = ctsk_typedef; t.spec = error_mark_node; } diff --git a/gcc/testsuite/c-c++-common/spellcheck-pr107583.c b/gcc/testsuite/c-c++-common/spellcheck-pr107583.c new file mode 100644 index 00000000000..86a9e7dbcb6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/spellcheck-pr107583.c @@ -0,0 +1,10 @@ +struct s1 { + time_t mytime; /* { dg-error "unknown type name 'time_t'" "c error" { target c } } */ + /* { dg-error "'time_t' does not name a type" "c++ error" { target c++ } .-1 } */ + /* { dg-message "'time_t' is defined in header" "hint" { target *-*-* } .-2 } */ +}; + +struct s2 { + unsinged i; /* { dg-error "unknown type name 'unsinged'; did you mean 'unsigned'." "c error" { target c } } */ + /* { dg-error "'unsinged' does not name a type; did you mean 'unsigned'." "c++ error" { target c++ } .-1 } */ +}; -- 2.26.3