From patchwork Thu Apr 13 18:59:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 83064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1254026vqo; Thu, 13 Apr 2023 12:00:45 -0700 (PDT) X-Google-Smtp-Source: AKy350a8XkfujZLYAA3OH+yNEpBWDlqatx1XsvcH+vdnX6LCJqoLITOlEcEvxFiO/a895gIkDDcx X-Received: by 2002:a17:906:1c5b:b0:94a:8b47:8c66 with SMTP id l27-20020a1709061c5b00b0094a8b478c66mr3842469ejg.30.1681412445200; Thu, 13 Apr 2023 12:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681412445; cv=none; d=google.com; s=arc-20160816; b=kTP4kvizl6E0/SyZ8xA0RAxBbLUEeaqJF+ZpgAVGtGmH52RHvAL4c65VuMwp8YPiCs AIe55SUkKa/mXiB6OJ93anOYUPtiGzz/ZIZArkZY5Fj2Twv6QC0gGzm8S9vvbjCP8CIt o5DEzEArSIAyMoFOtdpdtSxlI8hG+fMilelgGrF6awI5GwqdJJ5yr9tOcSMgNgIf1N/S 7kEm7nP1j8gP3plssqOLNikgT0EqOqkPm8oPeJebKpn9Ol0YvYRvCDBHM6SXvNXQHAC1 1sxxTYEgoI9ouUp2pC3rjshPzSeGsCXcbuONIPdbDiRXJ+76wWfeRN7lexoThkh8Ss6t JIIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=PK2Gb/UjBPoBAoEy8JwWdHoHJHiA3RU3rrNuZElT3w4=; b=ZZstLo/P0nrEppYLOagD5Tguwrir1n89woYN73CpQPHyqwzsC0u0ge689AmyFnv2+Y 6S9Qo10z3UTws1Bt8lcl/jA0AsASiOL8kURQRkkgkYqecxcFXMPVr4ESPQHi98DtbQ/B 6WAvyM8+SOm3WmgHYg+sfCXJnJut2BvCnBM6l4r4zJ8OIbdKVQasOUkzFK9Wf9Yvxenu UxTbZAW3wmPQg/HgwwR0FYrMMMzZPAJ4c6j1lwDhu9uTp8W0/3V+ISrjNN56rKXRqvGq PdfwSaL9eOUEOCIqVn+aDPdqOiW2EmrB2qHjcW3uxB+YE5ZCBgqbXzoIldfYlCdj3Zdc haUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ed5vnYG8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ka5-20020a170907920500b0094a55def0ffsi2486731ejb.300.2023.04.13.12.00.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 12:00:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ed5vnYG8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA67A385697A for ; Thu, 13 Apr 2023 19:00:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA67A385697A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681412415; bh=PK2Gb/UjBPoBAoEy8JwWdHoHJHiA3RU3rrNuZElT3w4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ed5vnYG8nFiRzxa3GPgXib/gyH8D9OWma9llR4D0kewgfYtKvE/Oc0CzuIHWd1i7l gybUBu+/EUKabQ5KkixE6qaE17QAiJiWHz/e2PpAGthLdPpGAvUezeua3zh/vhqJ9A 2o8NGfIXlarm1c7hzOYbPuZFkzBZoo+dsyeWcAvA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 BA1583858C2C for ; Thu, 13 Apr 2023 18:59:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA1583858C2C Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-232-ITDo5H94PZSDbvMQf2QO1w-1; Thu, 13 Apr 2023 14:59:27 -0400 X-MC-Unique: ITDo5H94PZSDbvMQf2QO1w-1 Received: by mail-qt1-f198.google.com with SMTP id v24-20020a05622a189800b003e0e27bbc2eso11600809qtc.8 for ; Thu, 13 Apr 2023 11:59:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681412366; x=1684004366; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PK2Gb/UjBPoBAoEy8JwWdHoHJHiA3RU3rrNuZElT3w4=; b=EHc8noq30E+HLssdGZBJ7WYgksvqhdXEX6IeDveFV81hslGQHEzUiYRL+FXf29uBqA orz3HFqLGnrMZ4ebQ+hBf2TOkah8xN5jcW/yxjaE/BBv1Q3l6LSmqVAH98JcMISIpmuk Yr+gIzOP2IZYrUVlVU0IP9mep26AwF4qI5GpqsVaZZmJIPqgUEMAnQjmIrFS2OCYlhYy q71JK3SA3Q9TwCdCRSrkWq/RWcGsghb2E9t5AY52vB8HMEIUb/bKMwcMKuqAC4nP+l9j Bb6IxK85JHoY7PB7DNdmWot18gdNbGA/SsGqChXD6sdwnkcnHYlqbEvJ9mubN0733NWn gBZw== X-Gm-Message-State: AAQBX9dDv1ycACiCxFCxAY+t/i8saK3EjWEoDHeVJyKUF85Mm2zgGcAc 12mi3tIe1qeMNzJPw/3ufj/W3Skyp74vdA5QI2KUV4g/SQzsClFtnLoTi6mhSGkgNquhGOvhZWh SfjY6TBSGq0QMPMlob6LZMVg9qEHhMlTdT8XRc6U+WNWc80XOd6vrHkJIcF8kVrbyDfrztpt31w == X-Received: by 2002:a05:622a:151:b0:3ea:3e86:1b74 with SMTP id v17-20020a05622a015100b003ea3e861b74mr2927006qtw.17.1681412366319; Thu, 13 Apr 2023 11:59:26 -0700 (PDT) X-Received: by 2002:a05:622a:151:b0:3ea:3e86:1b74 with SMTP id v17-20020a05622a015100b003ea3e861b74mr2926982qtw.17.1681412365853; Thu, 13 Apr 2023 11:59:25 -0700 (PDT) Received: from jason.com ([66.31.49.15]) by smtp.gmail.com with ESMTPSA id f13-20020ac8068d000000b003e3918f350dsm686385qth.25.2023.04.13.11.59.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:59:25 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] c++: make cxx_incomplete_type_diagnostic return bool Date: Thu, 13 Apr 2023 14:59:20 -0400 Message-Id: <20230413185921.2201433-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763088736410847699?= X-GMAIL-MSGID: =?utf-8?q?1763088736410847699?= Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- Like other diagnostic functions that might be silenced by options, it should return whether or not it actually emitted a diagnostic. gcc/cp/ChangeLog: * typeck2.cc (cxx_incomplete_type_diagnostic): Return bool. * cp-tree.h (cxx_incomplete_type_diagnostic): Adjust. --- gcc/cp/cp-tree.h | 8 ++++---- gcc/cp/typeck2.cc | 34 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 20 deletions(-) base-commit: 66c7257b675068fe62505d74873371fd0508b499 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 622752ae4e6..a14eb8d0b9a 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8155,7 +8155,7 @@ extern void maybe_warn_pessimizing_move (tree, tree, bool); /* in typeck2.cc */ extern void require_complete_eh_spec_types (tree, tree); -extern void cxx_incomplete_type_diagnostic (location_t, const_tree, +extern bool cxx_incomplete_type_diagnostic (location_t, const_tree, const_tree, diagnostic_t); inline location_t loc_or_input_loc (location_t loc) @@ -8178,12 +8178,12 @@ cp_expr_loc_or_input_loc (const_tree t) return cp_expr_loc_or_loc (t, input_location); } -inline void +inline bool cxx_incomplete_type_diagnostic (const_tree value, const_tree type, diagnostic_t diag_kind) { - cxx_incomplete_type_diagnostic (cp_expr_loc_or_input_loc (value), - value, type, diag_kind); + return cxx_incomplete_type_diagnostic (cp_expr_loc_or_input_loc (value), + value, type, diag_kind); } extern void cxx_incomplete_type_error (location_t, const_tree, diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc index c56b69164e2..76a7a7f6b98 100644 --- a/gcc/cp/typeck2.cc +++ b/gcc/cp/typeck2.cc @@ -292,7 +292,7 @@ cxx_incomplete_type_inform (const_tree type) and TYPE is the type that was invalid. DIAG_KIND indicates the type of diagnostic (see diagnostic.def). */ -void +bool cxx_incomplete_type_diagnostic (location_t loc, const_tree value, const_tree type, diagnostic_t diag_kind) { @@ -304,7 +304,7 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value, /* Avoid duplicate error message. */ if (TREE_CODE (type) == ERROR_MARK) - return; + return false; if (value) { @@ -336,7 +336,7 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value, break; case VOID_TYPE: - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of %qT", type); break; @@ -346,7 +346,7 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value, type = TREE_TYPE (type); goto retry; } - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of array with unspecified bounds"); break; @@ -365,12 +365,12 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value, add a fix-it hint. */ if (type_num_arguments (TREE_TYPE (member)) == 1) richloc.add_fixit_insert_after ("()"); - emit_diagnostic (diag_kind, &richloc, 0, + complained = emit_diagnostic (diag_kind, &richloc, 0, "invalid use of member function %qD " "(did you forget the %<()%> ?)", member); } else - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of member %qD " "(did you forget the %<&%> ?)", member); } @@ -380,38 +380,38 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value, if (is_auto (type)) { if (CLASS_PLACEHOLDER_TEMPLATE (type)) - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of placeholder %qT", type); else - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of %qT", type); } else - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of template type parameter %qT", type); break; case BOUND_TEMPLATE_TEMPLATE_PARM: - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of template template parameter %qT", TYPE_NAME (type)); break; case TYPE_PACK_EXPANSION: - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of pack expansion %qT", type); break; case TYPENAME_TYPE: case DECLTYPE_TYPE: - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of dependent type %qT", type); break; case LANG_TYPE: if (type == init_list_type_node) { - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "invalid use of brace-enclosed initializer list"); break; } @@ -419,20 +419,22 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value, if (value && TREE_CODE (value) == COMPONENT_REF) goto bad_member; else if (value && TREE_CODE (value) == ADDR_EXPR) - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "address of overloaded function with no contextual " "type information"); else if (value && TREE_CODE (value) == OVERLOAD) - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "overloaded function with no contextual type information"); else - emit_diagnostic (diag_kind, loc, 0, + complained = emit_diagnostic (diag_kind, loc, 0, "insufficient contextual information to determine type"); break; default: gcc_unreachable (); } + + return complained; } /* Print an error message for invalid use of an incomplete type.