From: Jason Merrill <jason@redhat.com>
To: Markus Faehling <markus@faehling.com>, gcc@gcc.gnu.org
Subject: Re: GCC/clang warning incompatibility with unused private member variables
Date: Fri, 11 Jun 2021 16:03:34 -0400 [thread overview]
Message-ID: <7aa76520-3250-1bda-9fd9-baee1e83cd44@redhat.com> (raw)
In-Reply-To: <5f5ddb1f-39f7-d858-e1c5-afff73043df3@faehling.com>
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
next prev parent reply other threads:[~2021-06-11 20:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-11 19:37 Markus Faehling
2021-06-11 19:59 ` Gabriel Ravier
2021-06-11 20:03 ` Jason Merrill [this message]
2021-06-11 20:35 ` Jakub Jelinek
2021-06-13 17:19 ` Jason Merrill
2021-06-11 22:14 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7aa76520-3250-1bda-9fd9-baee1e83cd44@redhat.com \
--to=jason@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=markus@faehling.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).