https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92562

            Bug ID: 92562
           Summary: Allow [[maybe_unused]] in class member declaration
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: romain.geissler at amadeus dot com
  Target Milestone: ---

Hi,

The following snippet is accepted by clang but reject by gcc (any version I
tested: 8, 9, and trunk):

class A
{
    // Maybe unused to silence clang error: private field '_i' is not used
[-Werror,-Wunused-private-field]
    int _i [[maybe_unused]];
};

It happens that this [[maybe_unused]] attribute may be needed in some cases to
silence the clang-specific warning -Wunused-private-field, in the strange cases
where you actually want to keep the unused member rather than removing it. An
alternative would be of course to use gcc pragma diagnostics, but still it
would be cool if gcc would accept [[maybe_unused]] on class member
declarations.

Today, gcc issues:
<source>:4:27: error: 'maybe_unused' attribute ignored [-Werror=attributes]
    4 |     int _i [[maybe_unused]];
      |                           ^
cc1plus: all warnings being treated as errors
Compiler returned: 1

Cheers,
Romain

Reply via email to