From patchwork Wed Jul 19 21:51:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 122845 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2727497vqt; Wed, 19 Jul 2023 14:52:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlGxlOisjwNpRYD78K/U8HP/7W3mtQp7vk3+bV3pPKrYIfS1vy4L1o7Rh9SqMb38dq0K2cN+ X-Received: by 2002:a05:6512:3b06:b0:4fb:7be5:4870 with SMTP id f6-20020a0565123b0600b004fb7be54870mr857936lfv.46.1689803532090; Wed, 19 Jul 2023 14:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689803532; cv=none; d=google.com; s=arc-20160816; b=KjIeqGwNuYloUAYY4+3kPaE60UT049/snk/g1vE9vMOXh8Wqvc8dVTTVMMbcJ5PXb5 6bZBoeAe1+gLMZONHm2LnFwrm0Rzc8JFGTKIuKD/zrmoT/JNoRnT67GfbdOBHX26zO/h atF2x8oex482Mf/Sskil0Gs80ZTjpuBnnGNBgW8OMkrag6KReWvd9ffYuiYWjC8PJYDj pLACg9CYE4GyX17MzdeeljWhv388fDZM3cJ2PGJbNJwQKViZpyvbAmo9ooyP2xH/O1BR 3rcQf3qM5LpzsjYFH+M21MQlVXv7PjzM3K6bLNBxIx2zznO+375BPPR3b2KCALGqdKKz aTrQ== 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=zoDSjbjXLZRbKwk7ZA0mzdXcO9eOeU/98ExLk4w/FkI=; fh=1drzuSgAqPtVUclta6Ecfzgh/wYNtWpRJF7yhohVT0I=; b=y/ezT9A0J4DoORaJm+x8KVPq0KbI94QPpx0xMU1+qTcbO94hgyKYgm5cIgSAf3qNBM UJubhUcVwLFbMcmSjBe0pKB/wO3cWUsgqqX70fZrLhaMbWlWlOPHmOHUtA2jbD+amqVp 6ipD1F+RUj6qD3zTpkUaw3VCbReyuxKohkQpXRtm/hQDqvCpDKoO+3Sg9bfNfyMPfuBu XO7IyU4sNYO2NNddlj+ewXazg0HLCR7LMOiMLyCn3B5rUicAFkgTeF+CckoKvXt1UsqF UblNPzqwL+H1U1K98XIpsCwif23NzN8orZwNuKFSuQaeftzYmDgWZu0k5Sw7VvuTU/WV cMmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SgH7CfFl; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x21-20020aa7d395000000b0051e26704e7csi3751986edq.7.2023.07.19.14.52.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 14:52:12 -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=SgH7CfFl; 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 C29DF3858000 for ; Wed, 19 Jul 2023 21:52:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C29DF3858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689803530; bh=zoDSjbjXLZRbKwk7ZA0mzdXcO9eOeU/98ExLk4w/FkI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=SgH7CfFlP255Ad/5Sixb4UyABo4WT84iS3wn7/fdx5fcaHcAO68lFxZNT82mVHgbJ SWGZjvSzOfaG6iCW74kLgKUc4XJLqhO7l0OQzUoSz/i5MxTehyHN313a90NDzi0A46 RK3q8ZPLegjcesOiHhbJ5QfixPzhb0eFj9xst6wc= 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 C654D3858C78 for ; Wed, 19 Jul 2023 21:51:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C654D3858C78 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-166-E2IbXpqYPXKJB1w7sgX9Zg-1; Wed, 19 Jul 2023 17:51:25 -0400 X-MC-Unique: E2IbXpqYPXKJB1w7sgX9Zg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 228AA936D21 for ; Wed, 19 Jul 2023 21:51:25 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.9.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0431DF6CCA; Wed, 19 Jul 2023 21:51:24 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: Improve printing of base classes [PR110745] Date: Wed, 19 Jul 2023 17:51:22 -0400 Message-ID: <20230719215122.513059-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 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_H4, 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 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771887428605399220 X-GMAIL-MSGID: 1771887428605399220 Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- This patch changes warning: missing initializer for member 'D::' [-Wmissing-field-initializers] to warning: missing initializer for member 'D::B' [-Wmissing-field-initializers] PR c++/110745 gcc/cp/ChangeLog: * error.cc (dump_simple_decl): Print base class name. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/base.C: New test. --- gcc/cp/error.cc | 2 ++ gcc/testsuite/g++.dg/diagnostic/base.C | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/g++.dg/diagnostic/base.C base-commit: b1ae46bdd19fc2aaea41bc894168bdaf4799be80 diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 31319aa9e87..8a5219a68a1 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -1177,6 +1177,8 @@ dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags) } else if (DECL_DECOMPOSITION_P (t)) pp_string (pp, M_("")); + else if (TREE_CODE (t) == FIELD_DECL && DECL_FIELD_IS_BASE (t)) + dump_type (pp, TREE_TYPE (t), flags); else pp_string (pp, M_("")); diff --git a/gcc/testsuite/g++.dg/diagnostic/base.C b/gcc/testsuite/g++.dg/diagnostic/base.C new file mode 100644 index 00000000000..1540414072e --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/base.C @@ -0,0 +1,16 @@ +// PR c++/110745 +// { dg-do compile { target c++17 } } +// { dg-options "-Wmissing-field-initializers" } + +struct B { int i; }; +struct D : B { + int x; + int y; +}; + +int +main () +{ + D d = {.x=1, .y=2}; // { dg-warning "missing initializer for member .D::B." } + (void)d; +}