linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fix warning about duplicate 'const'
@ 2004-03-08 23:43 Thomas Schlichter
  2004-03-09  0:14 ` Andrew Morton
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Schlichter @ 2004-03-08 23:43 UTC (permalink / raw)
  To: linux-kernel, Andrew Morton

[-- Attachment #1: Type: text/plain, Size: 804 bytes --]

Hi,

attached is a patch which fixes following wanings:

drivers/ide/ide-tape.c: In function `idetape_setup':
drivers/ide/ide-tape.c:4701: Warnung: duplicate `const'
drivers/video/matrox/matroxfb_g450.c: In function `g450_compute_bwlevel':
drivers/video/matrox/matroxfb_g450.c:129: Warnung: duplicate `const'
drivers/video/matrox/matroxfb_g450.c:130: Warnung: duplicate `const'
drivers/video/matrox/matroxfb_maven.c: In function `maven_compute_bwlevel':
drivers/video/matrox/matroxfb_maven.c:347: Warnung: duplicate `const'
drivers/video/matrox/matroxfb_maven.c:348: Warnung: duplicate `const'

This is done by removing the 'const' from the temporary variables of the min() 
and max() macros. For me it seems to have no negative impact, so please 
consider applying...

Best regards
   Thomas Schlichter

[-- Attachment #2: fix-duplicate-const-warning.diff --]
[-- Type: text/x-diff, Size: 678 bytes --]

--- linux-2.6.4-rc2/include/linux/kernel.h.orig	2004-03-04 07:16:34.000000000 +0100
+++ linux-2.6.4-rc2/include/linux/kernel.h	2004-03-09 00:34:21.980935992 +0100
@@ -168,15 +168,15 @@ extern void dump_stack(void);
  * "unnecessary" pointer comparison.
  */
 #define min(x,y) ({ \
-	const typeof(x) _x = (x);	\
-	const typeof(y) _y = (y);	\
-	(void) (&_x == &_y);		\
+	typeof(x) _x = (x);	\
+	typeof(y) _y = (y);	\
+	(void) (&_x == &_y);	\
 	_x < _y ? _x : _y; })
 
 #define max(x,y) ({ \
-	const typeof(x) _x = (x);	\
-	const typeof(y) _y = (y);	\
-	(void) (&_x == &_y);		\
+	typeof(x) _x = (x);	\
+	typeof(y) _y = (y);	\
+	(void) (&_x == &_y);	\
 	_x > _y ? _x : _y; })
 
 /*

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-08 23:43 [PATCH] fix warning about duplicate 'const' Thomas Schlichter
@ 2004-03-09  0:14 ` Andrew Morton
  2004-03-09  0:32   ` Linus Torvalds
  0 siblings, 1 reply; 15+ messages in thread
From: Andrew Morton @ 2004-03-09  0:14 UTC (permalink / raw)
  To: Thomas Schlichter; +Cc: linux-kernel, Linus Torvalds

Thomas Schlichter <thomas.schlichter@web.de> wrote:
>
> Hi,
> 
> attached is a patch which fixes following wanings:
> 
> drivers/ide/ide-tape.c: In function `idetape_setup':
> drivers/ide/ide-tape.c:4701: Warnung: duplicate `const'
> drivers/video/matrox/matroxfb_g450.c: In function `g450_compute_bwlevel':
> drivers/video/matrox/matroxfb_g450.c:129: Warnung: duplicate `const'
> drivers/video/matrox/matroxfb_g450.c:130: Warnung: duplicate `const'
> drivers/video/matrox/matroxfb_maven.c: In function `maven_compute_bwlevel':
> drivers/video/matrox/matroxfb_maven.c:347: Warnung: duplicate `const'
> drivers/video/matrox/matroxfb_maven.c:348: Warnung: duplicate `const'
> 
> This is done by removing the 'const' from the temporary variables of the min() 
> and max() macros. For me it seems to have no negative impact, so please 
> consider applying...

I think there was a reason for those consts in kernel.h's min() and max()
macros, but memory fails me.  Linus, do you recall?


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-09  0:14 ` Andrew Morton
@ 2004-03-09  0:32   ` Linus Torvalds
  2004-03-09  1:17     ` Thomas Schlichter
  0 siblings, 1 reply; 15+ messages in thread
From: Linus Torvalds @ 2004-03-09  0:32 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Thomas Schlichter, linux-kernel



On Mon, 8 Mar 2004, Andrew Morton wrote:
> > 
> > This is done by removing the 'const' from the temporary variables of the min() 
> > and max() macros. For me it seems to have no negative impact, so please 
> > consider applying...
> 
> I think there was a reason for those consts in kernel.h's min() and max()
> macros, but memory fails me.  Linus, do you recall?

I'm not 100% sure, but I think they are required to make a few other 
warnings go away. The fact that gcc complains about "const typeof" is a 
gcc misfeature, I think, and should be fixed there.

The warnings the extra "const" fixes is something like:

	int a;
	const int b;

	min(a,b)

where otherwise it would complain about pointers to different types when
comparing the type of the pointer. Or something.

		Linus

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-09  0:32   ` Linus Torvalds
@ 2004-03-09  1:17     ` Thomas Schlichter
  2004-03-09  1:32       ` Linus Torvalds
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Schlichter @ 2004-03-09  1:17 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton; +Cc: linux-kernel

Am Dienstag, 9. März 2004 01:32 schrieb Linus Torvalds:

~~ snip ~~

> The warnings the extra "const" fixes is something like:
>
> 	int a;
> 	const int b;
>
> 	min(a,b)
>
> where otherwise it would complain about pointers to different types when
> comparing the type of the pointer. Or something.

OK, I tested it and gcc 3.3.1 does not complain about this. So with my patch, 
the duplicate 'const' warning goes away here and no other warning occours...

But I don't know how other versions of gcc behave...

   Thomas


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-09  1:17     ` Thomas Schlichter
@ 2004-03-09  1:32       ` Linus Torvalds
  2004-03-09  1:35         ` Linus Torvalds
                           ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Linus Torvalds @ 2004-03-09  1:32 UTC (permalink / raw)
  To: Thomas Schlichter; +Cc: Andrew Morton, linux-kernel



On Tue, 9 Mar 2004, Thomas Schlichter wrote:
>
> Am Dienstag, 9. März 2004 01:32 schrieb Linus Torvalds:
> 
> ~~ snip ~~
> 
> > The warnings the extra "const" fixes is something like:
> >
> > 	int a;
> > 	const int b;
> >
> > 	min(a,b)
> >
> > where otherwise it would complain about pointers to different types when
> > comparing the type of the pointer. Or something.
> 
> OK, I tested it and gcc 3.3.1 does not complain about this. So with my patch, 
> the duplicate 'const' warning goes away here and no other warning occours...

Yeah, but do keep in mind that "something like" comment. I'm by no means 
sure that I remembered the exact reason correctly, and maybe they aren't 
really needed.

Also, I'm not convinced this isn't a gcc regression. It would be stupid to 
"fix" something that makes old gcc's complain, when they may be doing the 
right thing.

All that code was from early 2002 (around 2.4.9), so maybe somebody can 
find the full discussion on the linux-kernel archives from January 2002 or 
so?

			Linus

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-09  1:32       ` Linus Torvalds
@ 2004-03-09  1:35         ` Linus Torvalds
  2004-03-10  4:08         ` Keith Duthie
       [not found]         ` <20040310054918.GB4068@twiddle.net>
  2 siblings, 0 replies; 15+ messages in thread
From: Linus Torvalds @ 2004-03-09  1:35 UTC (permalink / raw)
  To: Thomas Schlichter; +Cc: Andrew Morton, linux-kernel



On Mon, 8 Mar 2004, Linus Torvalds wrote:
> 
> All that code was from early 2002 (around 2.4.9), so maybe somebody can 
> find the full discussion on the linux-kernel archives from January 2002 or 
> so?

Duh. Make that August/September 2001 or something. My BK dates are off for 
the early 2.4.x series, since I imported those as patches in early 2002.

		Linus

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-09  1:32       ` Linus Torvalds
  2004-03-09  1:35         ` Linus Torvalds
@ 2004-03-10  4:08         ` Keith Duthie
       [not found]         ` <20040310054918.GB4068@twiddle.net>
  2 siblings, 0 replies; 15+ messages in thread
From: Keith Duthie @ 2004-03-10  4:08 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Thomas Schlichter, Andrew Morton, linux-kernel

On Mon, 8 Mar 2004, Linus Torvalds wrote:

> All that code was from early 2002 (around 2.4.9), so maybe somebody can
> find the full discussion on the linux-kernel archives from January 2002 or
> so?

The thread in which the "const typeof" was introduced appears to be
"[IDEA+RFC] Possible solution for min()/max() war" from August/September
2001, and const typeof appears to have been introduced by Peter Breuer.

The arguments appear to largely be about signedness at that point. Some
mention is made of how bad -Wsign-compare is.
-- 
Just because it isn't nice doesn't make it any less a miracle.
     http://users.albatross.co.nz/~psycho/     O-   -><-

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
       [not found]         ` <20040310054918.GB4068@twiddle.net>
@ 2004-03-10  8:10           ` Gabriel Dos Reis
       [not found]           ` <20040310064001.GA7584@daikokuya.co.uk>
  2004-03-10 15:43           ` Linus Torvalds
  2 siblings, 0 replies; 15+ messages in thread
From: Gabriel Dos Reis @ 2004-03-10  8:10 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Linus Torvalds, Thomas Schlichter, Andrew Morton, linux-kernel, gcc

Richard Henderson <rth@twiddle.net> writes:

| On Mon, Mar 08, 2004 at 05:32:11PM -0800, Linus Torvalds wrote:
| > Also, I'm not convinced this isn't a gcc regression. It would be stupid to 
| > "fix" something that makes old gcc's complain, when they may be doing the 
| > right thing.
| 
| Problem is, that we're supposed to complain for
| 
| 	const const int x;
| and
| 	typedef const int t;
| 	const t x;

If I can help with an existing pratice, in C++ the former is
invalid and the second is valid -- the extra const is just silently
ignored.  Therefore, in C++ land the construct

| 	const int a;
| 	const __typeof(a) x;

would be accepted because __typeof__ acts like an unnamed typedef[*].
(And in effect, g++ will accept the code -- assuming you abstract over
initializers).  So, it does not look like an innovation here.
I don't know whether this should be another case for "C is different
from C++".


[*] Yes, an alias that does not introduce a name is strange alias, but
    that is what __typeof__ does.

-- Gaby

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
       [not found]           ` <20040310064001.GA7584@daikokuya.co.uk>
@ 2004-03-10 10:15             ` Joseph S. Myers
  0 siblings, 0 replies; 15+ messages in thread
From: Joseph S. Myers @ 2004-03-10 10:15 UTC (permalink / raw)
  To: Neil Booth
  Cc: Linus Torvalds, Thomas Schlichter, Andrew Morton, linux-kernel, gcc

On Wed, 10 Mar 2004, Neil Booth wrote:

> > seems dicey at best.  I'm not sure what to do about this, actually.
> > We might could do something with a new __nonqual_typeof(a) that
> > strips outermost type qualifications, but I havn't given that much
> > thought.
> 
> Or you could compile in C99 mode?

The gnu89-only kludge allowing compound literals in static initializers in 
certain cases, for compatibility with their old ill-defined semantics, is 
there because it was needed by Linux; I don't know if it's still needed, 
but that would prevent compiling in C99 mode where compound literals have 
only their C99 semantics as unnamed variables.

Simpler to restrict the pedwarns for duplicate qualifiers to (pedantic &&
!flag_isoc99) (in all the various cases warned for) and document this as
an extension from C99 that is accepted in C89/C90 mode.

-- 
Joseph S. Myers
jsm@polyomino.org.uk

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
       [not found]         ` <20040310054918.GB4068@twiddle.net>
  2004-03-10  8:10           ` Gabriel Dos Reis
       [not found]           ` <20040310064001.GA7584@daikokuya.co.uk>
@ 2004-03-10 15:43           ` Linus Torvalds
  2004-03-10 18:22             ` Richard Henderson
  2004-03-16  1:46             ` Mike Stump
  2 siblings, 2 replies; 15+ messages in thread
From: Linus Torvalds @ 2004-03-10 15:43 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Thomas Schlichter, Andrew Morton, linux-kernel, gcc



On Tue, 9 Mar 2004, Richard Henderson wrote:
> 
> seems dicey at best.  I'm not sure what to do about this, actually.
> We might could do something with a new __nonqual_typeof(a) that
> strips outermost type qualifications, but I havn't given that much
> thought.

Ok, let's try just stripping the "const" out of the min/max macros, and
see what complains. What the code _really_ wants to do is to just compare
two types for being basically equal, and in real life what Linux really
would prefer is to have "types" as first-class citizens and being able to
compare them directly instead of playing games. And we may end up having
that as a preprocessor phase (ie I might add it to the semantic parse
thing).

		Linus

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-10 15:43           ` Linus Torvalds
@ 2004-03-10 18:22             ` Richard Henderson
  2004-03-10 18:29               ` Andrew Haley
  2004-03-16  1:46             ` Mike Stump
  1 sibling, 1 reply; 15+ messages in thread
From: Richard Henderson @ 2004-03-10 18:22 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Thomas Schlichter, Andrew Morton, linux-kernel, gcc

On Wed, Mar 10, 2004 at 07:43:10AM -0800, Linus Torvalds wrote:
> Ok, let's try just stripping the "const" out of the min/max macros, and
> see what complains.

I remember what complains.  You get actual errors from

	const int x; 
	int y;
	min(x, y);


r~

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-10 18:22             ` Richard Henderson
@ 2004-03-10 18:29               ` Andrew Haley
  2004-03-10 18:35                 ` Paul Koning
  2004-03-10 18:37                 ` Richard Henderson
  0 siblings, 2 replies; 15+ messages in thread
From: Andrew Haley @ 2004-03-10 18:29 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Linus Torvalds, Thomas Schlichter, Andrew Morton, linux-kernel, gcc

Richard Henderson writes:
 > On Wed, Mar 10, 2004 at 07:43:10AM -0800, Linus Torvalds wrote:
 > > Ok, let's try just stripping the "const" out of the min/max macros, and
 > > see what complains.
 > 
 > I remember what complains.  You get actual errors from
 > 
 > 	const int x; 
 > 	int y;
 > 	min(x, y);

Can you explain *why* we have to produce a diagnostic for "const const
int" by default?

Can't we dispatch such things to "-pedantic" ?  Or treat "const const"
like "long long" used to be, a gcc extension?

Andrew.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-10 18:29               ` Andrew Haley
@ 2004-03-10 18:35                 ` Paul Koning
  2004-03-10 18:37                 ` Richard Henderson
  1 sibling, 0 replies; 15+ messages in thread
From: Paul Koning @ 2004-03-10 18:35 UTC (permalink / raw)
  To: aph; +Cc: rth, torvalds, thomas.schlichter, akpm, linux-kernel, gcc

>>>>> "Andrew" == Andrew Haley <aph@redhat.com> writes:

 Andrew> Richard Henderson writes:
 >> On Wed, Mar 10, 2004 at 07:43:10AM -0800, Linus Torvalds wrote: >
 >> Ok, let's try just stripping the "const" out of the min/max
 >> macros, and > see what complains.
 >> 
 >> I remember what complains.  You get actual errors from
 >> 
 >> const int x; int y; min(x, y);

 Andrew> Can you explain *why* we have to produce a diagnostic for
 Andrew> "const const int" by default?

 Andrew> Can't we dispatch such things to "-pedantic" ? 

I like that suggestion.

  paul


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-10 18:29               ` Andrew Haley
  2004-03-10 18:35                 ` Paul Koning
@ 2004-03-10 18:37                 ` Richard Henderson
  1 sibling, 0 replies; 15+ messages in thread
From: Richard Henderson @ 2004-03-10 18:37 UTC (permalink / raw)
  To: Andrew Haley
  Cc: Linus Torvalds, Thomas Schlichter, Andrew Morton, linux-kernel, gcc

On Wed, Mar 10, 2004 at 06:29:43PM +0000, Andrew Haley wrote:
> Can't we dispatch such things to "-pedantic" ?  Or treat "const const"
> like "long long" used to be, a gcc extension?

Willy has just reminded me about a patch he wrote to do just this.
Looking at it.


r~

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] fix warning about duplicate 'const'
  2004-03-10 15:43           ` Linus Torvalds
  2004-03-10 18:22             ` Richard Henderson
@ 2004-03-16  1:46             ` Mike Stump
  1 sibling, 0 replies; 15+ messages in thread
From: Mike Stump @ 2004-03-16  1:46 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Richard Henderson, Thomas Schlichter, Andrew Morton, linux-kernel, gcc

On Wednesday, March 10, 2004, at 07:43 AM, Linus Torvalds wrote:
> What the code _really_ wants to do is to just compare two types for 
> being basically equal, and in real life what Linux really would prefer 
> is to have "types" as first-class citizens and being able to compare 
> them directly instead of playing games.

:-)  Gosh, it sounds so sensible and easy.  Maybe someone will hammer 
on the std C folks for the feature...


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2004-03-16  1:52 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-08 23:43 [PATCH] fix warning about duplicate 'const' Thomas Schlichter
2004-03-09  0:14 ` Andrew Morton
2004-03-09  0:32   ` Linus Torvalds
2004-03-09  1:17     ` Thomas Schlichter
2004-03-09  1:32       ` Linus Torvalds
2004-03-09  1:35         ` Linus Torvalds
2004-03-10  4:08         ` Keith Duthie
     [not found]         ` <20040310054918.GB4068@twiddle.net>
2004-03-10  8:10           ` Gabriel Dos Reis
     [not found]           ` <20040310064001.GA7584@daikokuya.co.uk>
2004-03-10 10:15             ` Joseph S. Myers
2004-03-10 15:43           ` Linus Torvalds
2004-03-10 18:22             ` Richard Henderson
2004-03-10 18:29               ` Andrew Haley
2004-03-10 18:35                 ` Paul Koning
2004-03-10 18:37                 ` Richard Henderson
2004-03-16  1:46             ` Mike Stump

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).