From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 1F2EC385782E for ; Fri, 11 Jun 2021 19:59:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1F2EC385782E Received: by mail-wr1-x432.google.com with SMTP id a11so7226770wrt.13 for ; Fri, 11 Jun 2021 12:59:44 -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-transfer-encoding :content-language; bh=1Ptgqi9qvGjjlzml0YT/Ha06AFbpEZJzO2a2yw6cpXY=; b=oezbKWGCiUFCzN9pBuU3ng8F4SOvPeV0pR2XnbUEQaqe0cZRZ+CG8hJvbyL4NgIqjQ ShgBfR3IHWBlbMFT2QPj/WcghJXl4XPm88OrRyor6x32Dlr7UQegYzjzR6T97GG2MGJF 2/8idq4FnCDB3nd9iyXsUXYxSLbqRrnG2XbDSbCfTkf/9wGeu2kjo0TNusW4AdNHRzVc AM1deo9pZtBNX2csv7BxZzmZFWqUPs0UtM0C4RNXwOOvUuPgPxgbKqH7Mdt0wJiwKIsD Snv7bBXzoJQnCWVqAEQZ6EEJkrs9/GVwHT0vb1YAI4Sen7N8ZCoZAR+H1O8bpWToQheL C+IQ== X-Gm-Message-State: AOAM532BSYtlgVbtVDskSTK4gaMjfTNk7XOAfbcfa72Mnfh/7pcYoQ4V QN4x02rOpT9W87ke4tCWVxgjDKrCosgBLw== X-Google-Smtp-Source: ABdhPJwEXPg9c4pbeuhBn+2R2gd4YoFtS4W9RBNdAspd80D9V1acGQyZL1W9jITod+jo6wc6wf2yOQ== X-Received: by 2002:adf:a45a:: with SMTP id e26mr5900109wra.222.1623441582793; Fri, 11 Jun 2021 12:59:42 -0700 (PDT) Received: from [10.16.0.15] ([217.138.207.234]) by smtp.gmail.com with ESMTPSA id y8sm14890421wmi.45.2021.06.11.12.59.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Jun 2021 12:59:42 -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: Gabriel Ravier Message-ID: <60ed5a67-b6d8-1db0-b11a-40a8eb731433@gmail.com> Date: Fri, 11 Jun 2021 21:59:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <5f5ddb1f-39f7-d858-e1c5-afff73043df3@faehling.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, 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 19:59:45 -0000 On 6/11/21 9: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 > > Regards, > > Markus Faehling > It should be easy to solve this with some application of `#pragma GCC diagnostic` pragmas to temporarily disable `-Wattributes` on that specific line. I suppose it may look ugly, but it works.