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 914283858CD1 for ; Fri, 23 Jun 2023 16:08:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 914283858CD1 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=1687536508; 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: in-reply-to:in-reply-to:references:references; bh=OJQLiar0WBhAvTeUCcQ1dNm3WWX3PHXp8alZ0YhzcSQ=; b=Gk4QWzOEyYk3oQj1yQ6JXNeZWVTMEU/FiSOtV4U+PPU7RrKbk1FNh1Yr5xelZph3bM1xF5 jQ5W3C4w8W4O0NbaaD/Fda8Edzid2NENXro6MLd/PCcPYNldCSC9uhNBu/vLY+VSnRdpao HDQdlNvtNvQ+W+XnpiUn2l9DWCVtimI= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-ZGQ746DLOAGI4bF1qnuWww-1; Fri, 23 Jun 2023 12:08:26 -0400 X-MC-Unique: ZGQ746DLOAGI4bF1qnuWww-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-62fe5a90439so10305096d6.1 for ; Fri, 23 Jun 2023 09:08:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687536506; x=1690128506; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OJQLiar0WBhAvTeUCcQ1dNm3WWX3PHXp8alZ0YhzcSQ=; b=MAfOAt/UM/M7MkAK9w2Xnkgdgzg9hCu9bJ/5ItFJvy1mC6O322zfS/w2R7vxVAk20f eOQ2cdo/VMYSHffE/QfDx1JKOve2Y93NLpY6uMhM0CxVPSZoYZqcFRKjEiTqe6R3+JN6 gMa8rXZ2weAUGJtc16Eufy6/R7KVbNXYghuDCmqSRBFkj6oxobr40xWz0SW07U+FcOVQ 86Mg9Ci24/J0xinvOsCEsTyo7F9LjW3e61BWwl1CezuB/8/FBikBJY+RoE4fRsFXF8sz pVQaCnlhMm7H/6K+UXrnFhKZAesVLNMIlxtzVGCb5zEC5UZKwl1OWtXu8IzdD+TnnbAT nwvQ== X-Gm-Message-State: AC+VfDzL4p1yVkjWNxog4tQkRYTc0dTiD6C1pjLb1s3Dlnrbo4QS2MM8 xJXDCtHoseq54x9bV2F+Prnh9U3iPAYjeXPkZYwxQtTIRW6oS2IgxvpKxaZifxgbowqfDetpFQ1 c9VcZZnUbzFwOtcKmDg== X-Received: by 2002:ad4:5ae6:0:b0:628:731d:7ab4 with SMTP id c6-20020ad45ae6000000b00628731d7ab4mr32681421qvh.42.1687536506473; Fri, 23 Jun 2023 09:08:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7A5k3WTtA6+r+8hlGLotg6UkhZVevQ8hftK9A3i1GYX9EqP8K/mx5K+S2w1Sa+8erpO7c2Aw== X-Received: by 2002:ad4:5ae6:0:b0:628:731d:7ab4 with SMTP id c6-20020ad45ae6000000b00628731d7ab4mr32681392qvh.42.1687536506118; Fri, 23 Jun 2023 09:08:26 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id a14-20020a0cb34e000000b0062627f71b07sm5186166qvf.125.2023.06.23.09.08.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Jun 2023 09:08:25 -0700 (PDT) Message-ID: <97f85e9c-28a2-5e7b-16d5-b622d2eaa6b3@redhat.com> Date: Fri, 23 Jun 2023 12:08:23 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: PING: Re: [PATCH] c++: provide #include hint for missing includes [PR110164] To: Marek Polacek , David Malcolm Cc: gcc-patches@gcc.gnu.org References: <20230615002814.967814-1-dmalcolm@redhat.com> 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: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,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: On 6/22/23 11:50, Marek Polacek wrote: > On Wed, Jun 21, 2023 at 04:44:00PM -0400, David Malcolm via Gcc-patches wrote: >> I'd like to ping this C++ FE patch for review: >> https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621779.html > > Not an approval, but LGTM, though some nits below: > >> On Wed, 2023-06-14 at 20:28 -0400, David Malcolm wrote: >>> PR c++/110164 notes that in cases where we have a forward decl >>> of a std library type such as: >>> >>> std::array x; >>> >>> we omit this diagnostic: >>> >>> error: aggregate ‘std::array x’ has incomplete type and cannot be defined >>> >>> This patch adds this hint to the diagnostic: >>> >>> note: ‘std::array’ is defined in header ‘’; this is probably fixable by adding ‘#include ’ >>> >>> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. >>> OK for trunk? >>> >>> gcc/cp/ChangeLog: >>>         PR c++/110164 >>>         * cp-name-hint.h (maybe_suggest_missing_header): New decl. >>>         * decl.cc: Define INCLUDE_MEMORY.  Add include of >>>         "cp/cp-name-hint.h". >>>         (start_decl_1): Call maybe_suggest_missing_header. >>>         * name-lookup.cc (maybe_suggest_missing_header): Remove "static". >>> >>> gcc/testsuite/ChangeLog: >>>         PR c++/110164 >>>         * g++.dg/missing-header-pr110164.C: New test. >>> --- >>>  gcc/cp/cp-name-hint.h                          |  3 +++ >>>  gcc/cp/decl.cc                                 | 10 ++++++++++ >>>  gcc/cp/name-lookup.cc                          |  2 +- >>>  gcc/testsuite/g++.dg/missing-header-pr110164.C | 10 ++++++++++ >>>  4 files changed, 24 insertions(+), 1 deletion(-) >>>  create mode 100644 gcc/testsuite/g++.dg/missing-header-pr110164.C >>> >>> diff --git a/gcc/cp/cp-name-hint.h b/gcc/cp/cp-name-hint.h >>> index bfa7c53c8f6..e2387e23d1f 100644 >>> --- a/gcc/cp/cp-name-hint.h >>> +++ b/gcc/cp/cp-name-hint.h >>> @@ -32,6 +32,9 @@ along with GCC; see the file COPYING3.  If not see >>> >>>  extern name_hint suggest_alternatives_for (location_t, tree, bool); >>>  extern name_hint suggest_alternatives_in_other_namespaces (location_t, tree); >>> +extern name_hint maybe_suggest_missing_header (location_t location, >>> +                                              tree name, >>> +                                              tree scope); > > The enclosing decls omit the parameter names; if you do that, it may > fit on one line. > >>>  extern name_hint suggest_alternative_in_explicit_scope (location_t, tree, tree); >>>  extern name_hint suggest_alternative_in_scoped_enum (tree, tree); >>> >>> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc >>> index a672e4844f1..504b08ec250 100644 >>> --- a/gcc/cp/decl.cc >>> +++ b/gcc/cp/decl.cc >>> @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see >>>     line numbers.  For example, the CONST_DECLs for enum values.  */ >>> >>>  #include "config.h" >>> +#define INCLUDE_MEMORY >>>  #include "system.h" >>>  #include "coretypes.h" >>>  #include "target.h" >>> @@ -46,6 +47,7 @@ along with GCC; see the file COPYING3.  If not see >>>  #include "c-family/c-objc.h" >>>  #include "c-family/c-pragma.h" >>>  #include "c-family/c-ubsan.h" >>> +#include "cp/cp-name-hint.h" >>>  #include "debug.h" >>>  #include "plugin.h" >>>  #include "builtins.h" >>> @@ -5995,7 +5997,11 @@ start_decl_1 (tree decl, bool initialized) >>>         ;                       /* An auto type is ok.  */ >>>        else if (TREE_CODE (type) != ARRAY_TYPE) >>>         { >>> +         auto_diagnostic_group d; >>>           error ("variable %q#D has initializer but incomplete type", decl); >>> +         maybe_suggest_missing_header (input_location, >>> +                                       TYPE_IDENTIFIER (type), >>> +                                       TYPE_CONTEXT (type)); > > Maybe CP_TYPE_CONTEXT? > >>>           type = TREE_TYPE (decl) = error_mark_node; >>>         } >>>        else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type)))) >>> @@ -6011,8 +6017,12 @@ start_decl_1 (tree decl, bool initialized) >>>         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type)); >>>        else >>>         { >>> +         auto_diagnostic_group d; >>>           error ("aggregate %q#D has incomplete type and cannot be defined", >>>                  decl); >>> +         maybe_suggest_missing_header (input_location, >>> +                                       TYPE_IDENTIFIER (type), >>> +                                       TYPE_CONTEXT (type)); > > Here as well. > >>>           /* Change the type so that assemble_variable will give >>>              DECL an rtl we can live with: (mem (const_int 0)).  */ >>>           type = TREE_TYPE (decl) = error_mark_node; >>> diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc >>> index 6ac58a35b56..917b481c163 100644 >>> --- a/gcc/cp/name-lookup.cc >>> +++ b/gcc/cp/name-lookup.cc >>> @@ -6796,7 +6796,7 @@ maybe_suggest_missing_std_header (location_t location, tree name) >>>     for NAME within SCOPE at LOCATION, or an empty name_hint if this isn't >>>     applicable.  */ >>> >>> -static name_hint >>> +name_hint >>>  maybe_suggest_missing_header (location_t location, tree name, tree scope) >>>  { >>>    if (scope == NULL_TREE) >>> diff --git a/gcc/testsuite/g++.dg/missing-header-pr110164.C b/gcc/testsuite/g++.dg/missing-header-pr110164.C >>> new file mode 100644 >>> index 00000000000..15980071c38 >>> --- /dev/null >>> +++ b/gcc/testsuite/g++.dg/missing-header-pr110164.C > > Can we put the new test into g++.dg/diagnostic/? OK with the tweaks Marek suggests. Jason