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 ESMTP id 76CE9388982D for ; Sun, 13 Jun 2021 17:20:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 76CE9388982D Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-444-OOattc5XPGKlIf_0eXProw-1; Sun, 13 Jun 2021 13:20:00 -0400 X-MC-Unique: OOattc5XPGKlIf_0eXProw-1 Received: by mail-pj1-f71.google.com with SMTP id 4-20020a17090a1a44b029016e8392f557so4809585pjl.5 for ; Sun, 13 Jun 2021 10:20:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=FRBVA/2DV2GOsVtInZLJ52rUovAcZNJUUHQZRehZfwc=; b=DI4t4EUUKbPdXrmjMi7GQA5BlCD5BhmkKuc9DNuLY3i1LQTMU7Gbp50LN1VsWBlfjx 2nRnZW5yrFqe2KHm9zErPTio1qAqg8Uq12VW5rAJ/tDfdAujOfPL9G2x7SV3w+B2GOg4 IUF5mUjz7ZLV2aSyNVX8qTecP/jrRixsVtfaZaOLDM33GIqFM5pxmCj9la7btGI6m2Yp AFd9UiJ+yIDumOHiqqpdJUbUEYsaM8SaUZhS4jBfRVfO32orr+fsArkiicmhg19mksI9 sqpSBeiQB1dVFv05JGZmP+ZaeuPO4BjXEJEn/TZcb6O6QmpCE6q58SausVyNaHfiNic3 YN4Q== X-Gm-Message-State: AOAM532UJ6ZZqbNUBhXKPYccrDQ4eIDS7WW+i4dD8V4lqoxIFfC9fQMp aRBsgOxUY9esODyCvASViIxr6crnOuVu8xvaQnET9ETjYx5ZpmxkYNjVLzALzQbEug9sHEio8o+ pfao4iSyIPulNzwwby5vfUmg= X-Received: by 2002:a63:e14:: with SMTP id d20mr13763418pgl.35.1623604799235; Sun, 13 Jun 2021 10:19:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYaqkTjsx6Kjfmmz+qNdPsgN7UD7WHLQes/KoIXEvIcQ8TKjIdZfV+c/To9tb48BzAJzmlGckEd6m01VlcpUg= X-Received: by 2002:a63:e14:: with SMTP id d20mr13763396pgl.35.1623604798918; Sun, 13 Jun 2021 10:19:58 -0700 (PDT) MIME-Version: 1.0 References: <5f5ddb1f-39f7-d858-e1c5-afff73043df3@faehling.com> <7aa76520-3250-1bda-9fd9-baee1e83cd44@redhat.com> In-Reply-To: <7aa76520-3250-1bda-9fd9-baee1e83cd44@redhat.com> From: Jason Merrill Date: Sun, 13 Jun 2021 13:19:47 -0400 Message-ID: Subject: Re: GCC/clang warning incompatibility with unused private member variables To: Markus Faehling , gcc Mailing List X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, HTML_MESSAGE, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Jun 2021 17:20:13 -0000 On Fri, Jun 11, 2021 at 4:03 PM Jason Merrill wrote: > On 6/11/21 3:37 PM, Markus Faehling wrote: > > Hello, > > > > I'm currently facing a problem where I cannot get both gcc and clang > > warning-free simultaneously in my project. My code looks somewhat like > > this: > > > > class Test { > > int a_; > > void b() {}; > > }; > > > > This code gives me the(usually very useful) "-Wunused-private-field" > > warning on clang. But because I have the unused member on purpose, I > > would like to add the [[maybe_unused]] attribute to it: > > > > class Test { > > [[maybe_unused]] int a_; > > void b() {}; > > }; > > > > While this version is warning-free in clang, gcc has a "-Wattributes" > > warning because it ignores the [[maybe_unused]] warning. But I do not > > want to disable either of these warnings because they are still very > > useful in other situations. > > > > Would it be possible to ignore the "-Wattributes" warning for > > [[maybe_unused]] in places where other compilers might use the attribute? > > > > Demonstration on godbolt.org: https://godbolt.org/z/8oT4Kr5eM > > You can use #pragma to disable a warning for a particular section of code: > > #pragma GCC diagnostic push > #pragma GCC diagnostic ignored "-Wattributes" > class Test { > [[maybe_unused]] int a_; > void b() {}; > }; > #pragma GCC diagnostic pop > > But I also agree that GCC shouldn't warn here. I've pushed a change to trunk to stop warning about this case. Jason