On Fri, Jun 11, 2021 at 4:03 PM Jason Merrill <ja...@redhat.com> 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

Reply via email to