This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Add macros for diagnostic control, use for scanf %a tests
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Paul Eggert <eggert at cs dot ucla dot edu>
- Cc: <libc-alpha at sourceware dot org>
- Date: Wed, 26 Nov 2014 02:09:32 +0000
- Subject: Re: Add macros for diagnostic control, use for scanf %a tests
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 10 dot 1411252243090 dot 17237 at digraph dot polyomino dot org dot uk> <54752077 dot 7000002 at cs dot ucla dot edu> <alpine dot DEB dot 2 dot 10 dot 1411260040470 dot 17237 at digraph dot polyomino dot org dot uk> <5475349C dot 6040208 at cs dot ucla dot edu>
On Wed, 26 Nov 2014, Paul Eggert wrote:
> Joseph Myers wrote:
> > it doesn't work to have the pragmas in the same macro as the code
>
> Then how about using an inline function instead of a macro? Something like
> this:
>
> static inline __attribute__ ((__always_inline__)) int
> C99_sscanf (char const *str, char const *format, ...)
> {
> return sscanf (str, format, __builtin_va_arg_pack ());
> }
I'm doubtful about hiding warnings in ways that rely on the compiler not
being smart enough to see through them - it would be perfectly reasonable
for the compiler to warn in this case by doing format checking after
optimization. Warnings should be disabled in ways that clearly make it
incorrect for the compiler to warn.
> Similarly, if we're worried about fread_unlocked complaining about a
> zero-sized argument, perhaps we can write an inline wrapper for it; that
> should silence thw warning more accurately.
An inline wrapper would not be appropriate; these tests are specifically
using arguments with side-effects, and arguments with unusual types, to
verify that those work with the macro definitions the same way as they
would work with a normal function call (i.e. they are evaluated at least
once, and the floating-point arguments are converted to the correct
argument types). Using an inline wrapper would defect this testing.
--
Joseph S. Myers
joseph@codesourcery.com