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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id C95283855009 for ; Fri, 11 Jun 2021 20:03:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C95283855009 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-517-HFZPIkXsOIetwq8xuZCxmw-1; Fri, 11 Jun 2021 16:03:37 -0400 X-MC-Unique: HFZPIkXsOIetwq8xuZCxmw-1 Received: by mail-qk1-f200.google.com with SMTP id u6-20020ae9c0060000b02903ab0c9eea47so4925139qkk.16 for ; Fri, 11 Jun 2021 13:03:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=tvU8JH9YYX5D5UKwcHJLnZ4YJESu3zV5kpwlnDZC/D0=; b=Jsq7rDXMOI4gYjzRXHZMo+E2GO9c0UkU4a7QqxZBnA307znwTxaBvKAO1U+C0sPw3W h7/bJaER9aTDsNr9ABUh3F1YN6iCTjS1eipc8mNuDYYw6A+nx/edYJ24aO48mT+EhX+n dFlsHJB/lA6q14wbNyw+DwNHCkV6Os7yoaVumjN/IgDoLNDgYjiVDHYlNbJbRFeVD2th 0EB9B1ewmxKT555yIKoPMAOrXBUXM9d25i7ndrf9Msf201qPjFP025Yt29k5R2cjbAsP 1P7fKA38zeEQPU2/52LNztW4SaV086pqI48rlL66nGJ6saMx8/XQi5ObR+KRsFGdGUnO mxCw== X-Gm-Message-State: AOAM530POkVGJdG1ekCGbmZkn7yZzQCy31AetpbUgYbWaYrwciNbzeNv FWt2qcWq7c6mqK9ubchKmsYmX5NUjjSYONA4/YEOG4SW07wvjdFrLyGANdreMAFfwuEbajTrEPz UXT2+Np7AuhBb14XUA1EVhUGnAHLRD2lskapTuMKSxJK01elQs3agyKQ= X-Received: by 2002:ad4:4ea8:: with SMTP id ed8mr6555224qvb.58.1623441816661; Fri, 11 Jun 2021 13:03:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzGTZln96gbtT2MMFaDQraOyrP1b3sf74xRGOG4KGmPAhp2FC9xpll1t6vwvE+BF5GnefO5g== X-Received: by 2002:ad4:4ea8:: with SMTP id ed8mr6555202qvb.58.1623441816334; Fri, 11 Jun 2021 13:03:36 -0700 (PDT) Received: from [192.168.1.148] ([130.44.159.43]) by smtp.gmail.com with ESMTPSA id d16sm4672488qtj.69.2021.06.11.13.03.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Jun 2021 13:03:35 -0700 (PDT) Subject: Re: GCC/clang warning incompatibility with unused private member variables To: Markus Faehling , gcc@gcc.gnu.org References: <5f5ddb1f-39f7-d858-e1c5-afff73043df3@faehling.com> From: Jason Merrill Message-ID: <7aa76520-3250-1bda-9fd9-baee1e83cd44@redhat.com> Date: Fri, 11 Jun 2021 16:03:34 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <5f5ddb1f-39f7-d858-e1c5-afff73043df3@faehling.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, 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 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: Fri, 11 Jun 2021 20:03:42 -0000 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. Jason