Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Nov 2000 12:17:34 +0200
From:      Peter Pentchev <roam@orbitel.bg>
To:        Giorgos Keramidas <keramida@ceid.upatras.gr>
Cc:        hackers@freebsd.org
Subject:   Re: umask(2) and -Wconversion
Message-ID:  <20001107121734.D314@ringworld.oblivion.bg>
In-Reply-To: <20001107120511.A98074@gray.westgate.gr>; from keramida@ceid.upatras.gr on Tue, Nov 07, 2000 at 12:05:11PM %2B0200
References:  <20001107120511.A98074@gray.westgate.gr>

next in thread | previous in thread | raw e-mail | index | archive | help
In my experience, the problem is not only with umask(2) - GCC *is*
a bit stubborn about -Wconversion; I wonder if this is really a GCC bug :(

I'm having the same problems with many other functions when passing
integer constants - even if I explicitly cast them to a long or unsigned
long or plain unsigned int or whatever the particular function needs,
GCC seems to ignore the cast and whines about the conversion nonetheless :(

Can anybody else confirm this?  I can't dig out a code snippet right now,
but ISTR a recurring case of this when compiling with BDECFLAGS a program
which includes ncurses.h, then passes integer constants to init_pair()
or something similar.

G'luck,
Peter

-- 
If there were no counterfactuals, this sentence would not have been paradoxical.

On Tue, Nov 07, 2000 at 12:05:11PM +0200, Giorgos Keramidas wrote:
> While trying to compile libskey with various warnings enabled, I
> discovered the following funny thing about -Wconversion and umask(2),
> which caused libskey to fail to compile, because it compiles by default
> with -Werror which makes every warning fatal.
> 
> I found that the warning is caused when a program that calls umask(2) is
> compiled with -Wconversion.  The info page of gcc says about -Wconversion:
> 
>     `-Wconversion'
>          Warn if a prototype causes a type conversion that is different
>          from what would happen to the same argument in the absence of a
>          prototype.  This includes conversions of fixed point to floating
>          and vice versa, and conversions changing the width or signedness
>          of a fixed point argument except when the same as the default
>          promotion.
> 
>          Also, warn if a negative integer constant expression is implicitly
>          converted to an unsigned type.  For example, warn about the
>          assignment `x = -1' if `x' is unsigned.  But do not warn about
>          explicit casts like `(unsigned) -1'.
> 
> The following test program when compiled with -Wconversion shown below
> will always give a warning, even if I explicitly try to cast the
> argument of umask() to mode_t.
> 
>      1	#include <stdio.h>
>      2	#include <sys/stat.h>
>      3	
>      4	int main (void)
>      5	{
>      6		mode_t oldmask;
>      7	
>      8		oldmask = umask(0);
>      9		printf("The umask has changed\n");
>     10		umask(oldmask);
>     11		return 0;
>     12	}
> 
> The output given when I compile this with -Wconversion is:
> 
>     gray-charon:/home/charon/test% gcc -Wconversion test.c -o test
>     test.c: In function `main':
>     test.c:8: warning: passing arg 1 of `umask' with different width due to prototype
>     test.c:10: warning: passing arg 1 of `umask' with different width due to prototype
> 
> The problem is that even if I change line 8 to read:
> 
>      8		oldmask = umask((mode_t) 0);
> 
> the warning is still there.  Am I being a bit too strict with all these
> warnings here?  If not, does anyone else have any idea why umask(2) will
> always cause such a warning, and how I can go about correcting it?
> Casting obviously fails, so something else needs to be done.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001107121734.D314>