This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/51579] GCC should be able report a warning for usage of parameters marked with __attribute__((unused))


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51579

--- Comment #2 from Yann Droneaud <yann at droneaud dot fr> 2011-12-16 15:25:41 UTC ---
(In reply to comment #1)
> I don't think we should start warning each time an __attribute__((unused))
> parameter is actually used. In my experience that's absolutely common and
> pervasive.

That's why it must not be the default behavor,
so I'm not asking for inclusion in -Wunused.

> If the parameter is meant to *never* be used, should be completely
> removed, no?

Sometimes you cannot remove the parameter, since the function signature is
provided by, for example for a callback in some graphic toolkit.

What's the point of specifying that something is not used if your going to use
it anyway :)
If there's no penalty to put __attribute__((unused)), one mad developer could
put __attribute__((unused)) on all functions arguments, just in case.
(but in the end, it's easier to disable warning with -Wno-unused).

Having the warning could help programmer remember to remove the attribute which
is now, in turn, not used.

This would enforce some contract between the function declaration and its own
implementation.

> Or maybe what you are really asking for are unnamed parameters,
> like in C++, which indeed can be handy sometimes when dealing with ABI
> stability issues, etc? Seems something different, however.

Having the C++ unnamed parameter behavor could help, but would require some
preprocessor magic to be fully portable, for example.

    #if defined(__GNUC__) || defined(__cplusplus)
    # define UNUSED(name)
    #else
    # define UNUSED(name) unused_ ## name
    #endif

    int foo (int *ptr, int UNUSED(var))
    {
    }

Currently, one can do:

    #if defined(__GNUC__)
    # define UNUSED __attribute__((unused))
    #else
    # define UNUSED
    #endif

    int foo (int *ptr, int UNUSED var)
    {
    }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]