This is the mail archive of the gcc@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]

linux-2.5 min()/max() macros generate warnings with gcc-3.0.4 and gcc-3.2


This mail was first posted on lkml, but it should go there too, IMHO.

I first noticed this behaviour with gcc-3.0.4, and reproduced it with gcc-3.2.

HTH,

please CC me when replying to this message.


Begin forwarded message:

Date: Sat, 9 Nov 2002 01:21:20 +0100
From: "Thibaut VARENE" <varenet@parisc-linux.org>
To: linux-kernel@vger.kernel.org
Subject: linux-2.5 min()/max() macros generate warnings with gcc-3.0.4


Hi, 

I'm currently trying to cleanup some warnings on 2.5 kernel tree, (especially on parisc files), and i noticed the following warnings when compiling with gcc-3.0.4:

mm/vmscan.c: In function `shrink_caches':
mm/vmscan.c:746: warning: duplicate `const'
mm/swap_state.c: In function `free_pages_and_swap_cache':
mm/swap_state.c:299: warning: duplicate `const'

in swap_state.c, the faulty line is:

	int todo = min(chunk, nr);

where chunk is "const int" and nr is "int".

min()/max() are defined in include/linux/kernel.h:145

Here is the preprocessed compiler output for swap_state.c regarding the faulty line:

	int todo = ({ const typeof(chunk) _x = (chunk); const typeof(nr) _y = (nr); (void) (&_x == &_y); _x < _y ? _x : _y; });

which should be read in particular as:
	int todo = ({ const typeof(const int chunk) _x = (const int chunk);
with types expanded.

Therefore, it seems that gcc doesn't like the redundancy of 'const' around 'typeof'.

But, according to C99, section 6.7.3 "Type qualifiers", paragraph 4, "if the same qualifier appears more than once in the same specifier-qualifier-list, [...] the behavior is the same as if it appeared only once."

So gcc shouldn't be complaining...

FWIW, casting as follow solves the warning but it definitly _evil_, since we lose const'ness:

	int todo = min((int)chunk, nr);

HTH,


Thibaut VARENE
The PA/Linux ESIEE Team
http://pateam.esiee.fr/

PS: please CC me when answering.


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