[cfe-dev] rfc: winnt.h's UNREFERENCED_PARAMETER() vs clang's -Wunused-value

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Mon Oct 12 14:18:26 PDT 2015


I'd really rather not do 2. Fighting with MSVC CRT headers over va_start
has been pretty awkward. Users have reported issues with our header
override fails. I'd rather not start fighting with winnt.h.

I'm OK with 3, but I'm desensitized to having to do this kind of pattern
matching for __uuidof, etc. Maybe we should wait for another +1. :)

On Sat, Oct 10, 2015 at 2:50 PM, Nico Weber via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi,
>
> clang has a useful warning -Wunused-value that warns on things such as
> `4;` (this probably meant to say `return 4;`).
>
> winnt.h has a macro UNREFERENCED_PARAMETER(x) that's used to mark unused
> function parameters. It's somewhat commonly used on Windows, for example
> the default project generated by MSVC uses it a few times. The macro is
> defined as `#define UNREFERENCED_PARAMETER(x) (x)`, which means if you use
> it like it's intended:
>
>   void f(int x) {
>     UNREFERENCED_PARAMETER(x);
>   }
>
> then clang will emit a -Wunused-value warning for it. How do we want to
> fix this? Ideas:
>
> 1. Don't. Tell people to not use UNREFERENCED_PARAMETER().
> 2. Have a winnt.h wrapper in lib/Headers that undefines this macro,
> include_next's regular winnt.h, undefines it again, and then defines it to
> something that doesn't trigger -Wunused-value (say, `(void)p`, or `do {
> (void) P; } while (0)` or similar).
> 3. Change clang's Wunused-value to check if the unused value is expanded
> from a macro that was defined in a system header that's spelled
> UNREFERENCED_PARAMETER.
>
> 2 sounds like it has the highest chance of unintended side effects. 3 is a
> bit hacky, but seems nicest from a user's perspective and isn't worse than
> other things we do really.
>
> Other ideas? Opinions?
>
> Thanks,
> Nico
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151012/10aefa52/attachment.html>


More information about the cfe-dev mailing list