public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: a warning to implement
@ 2002-02-05 14:14 Robert Dewar
  2002-02-05 14:47 ` Michael Matz
                   ` (2 more replies)
  0 siblings, 3 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 14:14 UTC (permalink / raw)
  To: dewar, gdr; +Cc: aoliva, coola, gcc, pcarlini

Gaby, perhaps you could be so kind as to enlighten us with the wonderful
useful meanings that people argued for

  int a = a;

perhaps we will be so impressed by the suggestions that we will decide to
implement one of them, rather than generating a warning here. The only
suggestion I saw, which was to use this construct to turn off warnings,
seemed very peculiar and ill motivated. In other words, you could artificially
make it have this meaning, but I would find that most peculiar.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-11  7:30 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-11  7:30 UTC (permalink / raw)
  To: Dautrevaux, aoliva; +Cc: abraham, gcc

<We *already* have a warning that is enabled with -Wall for constructs
such as `T x = x;', and the warning is that `x' is being used
uninitialized.  Some earlier versions of GCC apparently didn't issue
this warning, or only do when optimization is enabled, but the fact is
that there is a warning already, and adding another IMHO would be
overkill.
>>

Sorry, I did get confused by the thread, yes, indeed that's a perfectly
fine warning, this is nothing more or less than an instance of using
x before it is initialized.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* RE: a warning to implement
@ 2002-02-11  7:13 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-11  7:13 UTC (permalink / raw)
  To: Dautrevaux, abraham, gcc

<<However there seems to be such a strong opposition to having this warning
installed by default in -Wall that I think we should at least provide it as
an additional warning flag; it's useful enough that we may get it.
>>

I don't see strong opposition. One person writing dozens of emails (Gaby)
does not add up to strong opposition. I would say that the consensus is
clearly to have it included in -Wall.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* RE: a warning to implement
@ 2002-02-11  6:53 Bernard Dautrevaux
  2002-02-11  7:19 ` Alexandre Oliva
  0 siblings, 1 reply; 105+ messages in thread
From: Bernard Dautrevaux @ 2002-02-11  6:53 UTC (permalink / raw)
  To: 'Per Abrahamsen', gcc

> -----Original Message-----
> From: Per Abrahamsen [mailto:abraham@dina.kvl.dk]
> Sent: Sunday, February 10, 2002 3:01 PM
> To: gcc@gcc.gnu.org
> Subject: Re: a warning to implement
> 
> 
> Gabriel Dos Reis <gdr@codesourcery.com> writes:
> 
> > What I'm saying is that if you want to be warned about that 
> construct
> > then you should explicitly turn on the appropriate flag.  In this
> > case, I do think -Walll should -not- turn that flag on.  
> 
> The manual says this about -Wall:
> 
>   `-Wall'
>        All of the above `-W' options combined.  This enables all the
>        warnings about constructions that some users consider
>        questionable, and that are easy to avoid (or modify to 
> prevent the
>        warning), even in conjunction with macros.
> 
> An example of a warning produced by -Wall:
> 
>   void foo (const char* p, char* q)
>   {
>     while (*q = *p)
>       { ++q; ++p; }
>   }
> 
>   test.cc: In function `void foo(const char *, char *)':
>   test.cc:3: warning: suggest parentheses around assignment 
> used as truth value
> 
> It is clear that _some_ users consider assignment as truth value
> questionable, and it is easy to avoid.  Thus, it is a good example of
> a -Wall warning.  Just to set the level we are talking about.
> 
> Are you saying the "T x = x" is less questionable or harder to work
> around than the above?
> 
> Personally, not being one of the super programmers on this 
> list, I have
> lost a couple of days work debugging errors caused by accidental use
> of the "T x = x" construct, which I at the time didn't even knew was
> legal, so I would have loved to have had a warning with -Wall, but
> wouldn't even have thought of searching for a separate flag.
> 

I can only agree with that :-)

However there seems to be such a strong opposition to having this warning
installed by default in -Wall that I think we should at least provide it as
an additional warning flag; it's useful enough that we may get it.

Anyway for me, that doesn't change a lot: I'm not even setting -Wall in my
makefiles: it's set up in some central place so that ALL compiles by ALL
developpers in my teams use it without even knowing that I've decided it;
thus I only have to add -Wself-initialize, or whatever it'll be called, to
this single location and all my programmers will have it :-)

I think this thread is now long enough we all refrain continuing this
religion war about whether this should be in -Wall or not (unless there is
some authoritative person that can get convinced and can rule about this
:-)).

Best regards, and thanks to all for the good work.

	Bernard

--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel:	+33 (0) 1 47 68 80 80
Fax:	+33 (0) 1 47 88 97 85
e-mail:	dautrevaux@microprocess.com
		b.dautrevaux@usa.net
-------------------------------------------- 

^ permalink raw reply	[flat|nested] 105+ messages in thread
* RE: a warning to implement
@ 2002-02-08  9:46 Bernard Dautrevaux
  2002-02-08 13:33 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Bernard Dautrevaux @ 2002-02-08  9:46 UTC (permalink / raw)
  To: 'Gabriel Dos Reis', dewar
  Cc: Bernard Dautrevaux, gcc, nathan, rsandifo

> -----Original Message-----
> From: Gabriel Dos Reis [mailto:gdr@codesourcery.com]
> Sent: Friday, February 08, 2002 5:29 PM
> To: dewar@gnat.com
> Cc: Dautrevaux@microprocess.com; gdr@codesourcery.com; 
> gcc@gcc.gnu.org;
> nathan@cs.bris.ac.uk; rsandifo@redhat.com
> Subject: Re: a warning to implement
> 
> 
> dewar@gnat.com (Robert Dewar) writes:
> 
> | >>| I think here we should REALLY had a warning;
> | 
> | Yes, good point from Bernard, I agree this is a case that 
> really needs
> | a warning.
> 
> There was no good point.  The class I showed wasn't designed to have a
> default constructor -- that is part of its specification.  The
> compiler (or Bernard) shouldn't insist on knowing more than the
> class-defisgner. 

OK; fine. But then you are saying that if a gun-holder wants to shoot
himself in the foot, nobody should warn him that this isn't *usually* a good
idea? an dyou insist that if someone is able to warn him, this warning
should *in no case* be emitted by default, but only if he choose to get it?

IMHO a compiler should warn the user of all possible cases where he may be
shooting into his own foot (or into another one's foot FWIW :-)); what I
could agree is that this warning could be disable by people that really want
to point the gun to their foot but knows there are cute enough to shoot just
between they toes, but the compiler should not assumbe blindly they are cute
enough.

After all, if you suddenly get a warning about a construct you're using
because you know what you do, you will then be inclined to RTFM and then
will discover the magic "-Wno-self-initialize" option that get you rid of
this anoying warning. 

But saving *you* the small burden of saying to the compiler "Hi, I'm a very
experienced programmer and I know exactly what I'm doing" seems not very
fair to all the "average" programmers that, incidentally, will *never* read
this thread because they don't even imagine what we are talking about.

> 
> There are already plenty of warnings there saying they know more than
> thge programmer -- and in effect thery don't -- ending with being
> completely unusable in modern C++; an example is -Weffc++ (or whatever
> it is called). 

OK; I 200% agree with you: "-Weffc++" is NOT a warning i would expect to be
activated by "-Wall". It's not a warning about dubious or dangerous
constructs, but a warning to help someone (obviously not you, nor me in
fact) adhere to some coding conventions that nobody request anybody to
accept.
 
	Bernard

--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel:	+33 (0) 1 47 68 80 80
Fax:	+33 (0) 1 47 88 97 85
e-mail:	dautrevaux@microprocess.com
		b.dautrevaux@usa.net
-------------------------------------------- 

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-08  8:23 Robert Dewar
  2002-02-08  9:09 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-08  8:23 UTC (permalink / raw)
  To: Dautrevaux, gdr; +Cc: dewar, gcc, nathan, rsandifo

>>| I think here we should REALLY had a warning;

Yes, good point from Bernard, I agree this is a case that really needs
a warning.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* RE: a warning to implement
@ 2002-02-08  6:57 Bernard Dautrevaux
  2002-02-08  8:21 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Bernard Dautrevaux @ 2002-02-08  6:57 UTC (permalink / raw)
  To: 'Gabriel Dos Reis', nathan; +Cc: Robert Dewar, rsandifo, gcc

> -----Original Message-----
> From: Gabriel Dos Reis [mailto:gdr@codesourcery.com]
> Sent: Wednesday, February 06, 2002 5:40 PM
> To: nathan@cs.bris.ac.uk
> Cc: Robert Dewar; gdr@codesourcery.com; rsandifo@redhat.com;
> gcc@gcc.gnu.org
> Subject: Re: a warning to implement
> 
> 
> Nathan Sidwell <nathan@acm.org> writes:
> 
> | Hi,
> | I've been reading this thread, and I still can't figure out how
> | 	T x = x;
> | as anything but undefined semantics. I'm talking C++ here.
> | [3.3.1]/1 gives an example about point of declaration, and says of
> | 	int x = x;
> | 	Here ... is initialized with its own (indeterminate) value.
> | 
> | But, that assignment requires an lvalue to rvalue conversion on 'x',
> | and [4.1] says
> | 	'or if the object is uninitialized,... undefined behaviour'
> 
> The object isn't uninitialized; it is initialized with an
> indeterminated value. The point is precisely to give an explicit hint
> to the compiler to assign (if possible) to assign a singular value to
> x (pretty much in the same way you might assign a SNaN to a floating
> point to prevent use before explicit assignment with determinate
> value. 
> 
> | So it appears that we've got undefined behaviour for any POD T.
> 
> Except when T = char or unsigned char.
> 
> | For a class T, we could be calling the copy ctor T(T const &).
> | Reference binding at [8.3.1]/4 says a reference must be bound to a
> | `valid object'. I suppose that it is ok to reference bind to an
> | object of indeterminate value.
> 
> The following is OK:
> 
>   struct Node {
>      Node* link;
>      Node(Node& n) : link(&n) { }
>   };
> 
>   int main()
>   {
>      T x = x;
>   }
> 
> and is a canonical example of use for user-defined-type.

I think here we should REALLY had a warning; in fact you have here a class
which explicitely do NOT have a default constructor, and then we create an
un-constructed object value. 

OTOH, if I have

class Node {
      Node* link;
public:
	Node() { link = 0; }
	~Node() { delete link; }
	Node(Node* n) : link(n) { }
	Node(Node& n) : link(&n) { }
};

int main() {
	T x = x;
}

Then I' most surely have, in my Node class, taken all possible precautions
to avoid any use of undefined pointer values, yet the given main will most
surely crash with some kind of SIGSEGV ;-(

So IMNSHO, the warning IS needed and should be on ASAP, so at least in
-Wall.

Just my .02euro

	Bernard

--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel:	+33 (0) 1 47 68 80 80
Fax:	+33 (0) 1 47 88 97 85
e-mail:	dautrevaux@microprocess.com
		b.dautrevaux@usa.net
-------------------------------------------- 

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06 13:55 mike stump
  0 siblings, 0 replies; 105+ messages in thread
From: mike stump @ 2002-02-06 13:55 UTC (permalink / raw)
  To: dewar, gdr; +Cc: gcc, nathan, rsandifo

> To: dewar@gnat.com, gdr@codesourcery.com
> Cc: gcc@gcc.gnu.org, nathan@cs.bris.ac.uk, rsandifo@redhat.com
> Date: Wed,  6 Feb 2002 15:23:48 -0500 (EST)
> From: dewar@gnat.com (Robert Dewar)

> You seem to be assuming that of necessity a char object can contain
> only valid representations. This is definitely not true on all
> implementations.

It is certainly true on all C and C++ implementations.  gcc is first,
and foremost, a C/C++ compiler.  We wind up with the reality that
while what you say might be true, no such implementation can host
either a C or C++ compiler, and no such implementation is interesting
while discussing gcc.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06 13:02 Robert Dewar
  2002-02-07 10:51 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-06 13:02 UTC (permalink / raw)
  To: gdr, jbuck; +Cc: aoliva, dewar, gcc, phil

>>It is defined to copy a signalling NaN.

Not in this situation it is not! That's because

   int a = a;

is undefined, so any assurance that an ordinary assignment or initialization
may give does not apply in this case.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06 12:29 Robert Dewar
  2002-02-06 12:35 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-06 12:29 UTC (permalink / raw)
  To: dewar, gdr; +Cc: gcc, nathan, rsandifo

<<  Certain object representations need not represent a value of the
  object type.  If the stored value of the object has such a
  representation and is read by an lvalue expression that does not
  have character type, the behavior is undefined.  If such a
  representation is produced by a side effect thaty modifies all or
  any part of the object by an lvalue expression that does not have
  character type, the behavior is undefined.  Such a representation is
  called a trap represetation.
>>

You seem to be assuming that of necessity a char object can contain only
valid representations. This is definitely not true on all implementations.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06 12:04 Robert Dewar
  2002-02-06 12:22 ` Joe Buck
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-06 12:04 UTC (permalink / raw)
  To: gdr, jbuck; +Cc: aoliva, dewar, gcc, phil

But Gaby, right now, the construct

 int a = a;

produces an undefined result, so no one can use it. It might suppress
warnings in one version of gcc, but then someone might submit a patch
that causes it to have some disastrous effect, and no one would have
a right to complain, since if they are using this, they are using an
undocumented behavior, and have no right to count on it.

So the idea of excluding this from -Wall would make sense ONLY if you
make the effect of suppressing warnings an official part of the gcc
semantics. In short only the following make sense:

1. Make this an official construct for the purpose of suppressing warnings
for uninitialized variables, and document that it has no other (ill) effect.
You can then decide whether to put the warning for this non-standard
construct in -Wall or not.

2. Leave this as it is now, undefined, in which case there can be no objection
to it being in -Wall, and indeed those people injudiciously using this
consruct to suppress warnings will be warned that this usage is neither
blessed nor guaranteed.

Frankly I would be surprised if you could get a consensus for approach 1.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06  9:03 Robert Dewar
  2002-02-06  9:19 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-06  9:03 UTC (permalink / raw)
  To: gdr, nathan; +Cc: dewar, gcc, rsandifo

>>Except when T = char or unsigned char.

Please explain why you think this is an exception?

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06  8:40 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-06  8:40 UTC (permalink / raw)
  To: dewar, gdr; +Cc: gcc, rsandifo

I asked where it said in the documentation that

  int a = a;

has a well defined meaning, and you replied that you had
already answered that questoin, and I had ignored the answer.

Perhaps you did not read my message carefully and realize
that it was referring only to the int case?

We are only discussing warnings here for the cases where
the semantics is clearly undefined in the standard. My
question was whether gcc had given defined semantics to
any of these cases. My understanding is that the answer
to this question is no, despite your most recent message
on the subject.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06  8:29 Robert Dewar
  2002-02-06  8:29 ` Gabriel Dos Reis
  2002-02-06  8:38 ` Nathan Sidwell
  0 siblings, 2 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-06  8:29 UTC (permalink / raw)
  To: gdr, rsandifo; +Cc: dewar, gcc

<<Ah, I think I can live with that.  However, someone gave an example of
a GNU package where self-initialization was used.  I suppose that your
proposal won't warn about his code. For T = int, I'm still not
convinced although I'm understanding your arguments.
>>

What's going on here? You claimed in your last message that the GCC doc
already gave a direct meaning for the case of T = int, but the above
message seems inconsistent with that.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06  8:03 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-06  8:03 UTC (permalink / raw)
  To: dewar, gdr; +Cc: gcc, rsandifo

>>I already did, but you choosed to ignore it.

No, sorry, I just looked at the complete file of messages from you, and
there was discussion for some cases other than int, but not for int. so
if you pointed to the doc for int, unfortunately the blasted email system
must have lost the message, so could you point it out again, sorry for
the inconvenience.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06  7:51 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-06  7:51 UTC (permalink / raw)
  To: gdr, rsandifo; +Cc: dewar, gcc

<<My suggestion was to warn only about cases when we can detect the
behaviour is not documented or well-defined.  The option itself could be
documented that way.  If the behaviour of more self-initializers becomes
defined over time, the number of cases we warn about would go down.
>>

Of course no one is suggesting warnings where the meaning is well defined.
Just keep focussed on

  int a = a;

which is the focus of this discussion, has no known or defined meaning,
cannot be used today with any useful effect, is known to be undefined,
and which should give a warning!

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06  6:56 Robert Dewar
  2002-02-06  8:01 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-06  6:56 UTC (permalink / raw)
  To: gdr, rsandifo; +Cc: dewar, gcc

<Now you'll have to argue why you're stopping something documented used
to work as documented.
>>

Please explain where in the documentation the meaning of

  int x = x;

is defined. I can't find it.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06  6:35 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-06  6:35 UTC (permalink / raw)
  To: gcc, jss

<<So it looks like there is divine permission for a warning :-)  (yes I know
Bjarne is not the standard).
>>

No, but one can hadly fault his reasonable statement here, which is a nice
summing up of this strange thread.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06  2:00 Jeremy Sanders
  0 siblings, 0 replies; 105+ messages in thread
From: Jeremy Sanders @ 2002-02-06  2:00 UTC (permalink / raw)
  To: gcc

(apologies if you use threading - it's hard to reply to the digest mode)

Interestingly Bjarne Stroustrup writes in The C++ Programming Language
(Special Edition), Section 4.9.4:

<<
The scope of a name starts at its point of declaration; that is, after the
complete declarator and before the initializer. This implies that a name
can be used even to specify its own initial value. For example:

int x;
void f3()
{
 int x = x; // perverse: initialise x with its own (unitialised) value
}

This is not illegal, just silly. A good compiler will warn if a variable
is used before it has been set (also see Section 5.9[9]).
>>

So it looks like there is divine permission for a warning :-)  (yes I know
Bjarne is not the standard).

Jeremy

-- 
Jeremy Sanders <jss@ast.cam.ac.uk>  http://www-xray.ast.cam.ac.uk/~jss/
Pembroke College, Cambridge. UK   Institute of Astronomy, Cambridge. UK


^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-06  0:03 Robert Dewar
  2002-02-06 10:50 ` Joe Buck
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-06  0:03 UTC (permalink / raw)
  To: aoliva, dewar; +Cc: gcc, gdr, jbuck, phil

<<I've only proposed it as a feature.  I don't think this is
documented as such.
>>

So no one could actually be using 

int a = a;

for any useful purpose right now as I understand it, so I am at a complete
loss to understand Gaby's claim that some people think this is useful.
I could see how some people might be able to give it a useful meaning
(but I object in principle to encouraging people to write undefined C
counting on it to have peculiar meanings in compiler), but Gaby claimed
that some people think it is useful now, and I just can't understand that.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05 20:27 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 20:27 UTC (permalink / raw)
  To: dewar, gdr; +Cc: gcc

<<I'm not sure I can represent on this public list, opinions expressed
on closed mailing-lists.  However, you might want to consult
c++std-core archive.  You'll discover people have use of
self-initialisation even if you cannot imagine such use.
>>

Well they can only have "use" of this if the compiler in question defines
some special effect. Otherwise they are writing undefined stuff that could
have an arbitrary effect, and I really don't see how that could ever be
useful.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05 20:16 Robert Dewar
  2002-02-05 21:00 ` Alexandre Oliva
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 20:16 UTC (permalink / raw)
  To: gdr, phil; +Cc: gcc, jbuck

One thing I realize I am confused about now, is it *currently* the case
that gcc documents that

   int a = a;

suppresses warnings on a, or is this just a proposed feature? I certainly
never read anything like this in the documentation.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05 20:12 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 20:12 UTC (permalink / raw)
  To: dewar, matzmich; +Cc: gcc, gdr

<<As already noted it's fairly irrelevant that you find it peculiar or
useless, or anything.  What is relevant, is that there obviously are
people who think it's usefull for that purpose.  Perhaps you can suggest
an equivalent alternative to suppress the warning in question in certain
circumstances.
>>

My objection to having this suppress the warning is that it seems entirely
arbitrary. I would find it no less arbitrary to say that the warning is
suppressed if the comment /* no warnings please */ is found after
the declaration, and it would certainly be more readable. 

^ permalink raw reply	[flat|nested] 105+ messages in thread
* RE: a warning to implement
@ 2002-02-05 20:07 Robert Dewar
  2002-02-06 11:06 ` Joe Buck
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 20:07 UTC (permalink / raw)
  To: gdr, jbuck, sk.mail; +Cc: Dautrevaux, aoliva, coola, dewar, gcc, pcarlini, tim

>>Perhaps there should be an option to enable *all* warnings?

Sounds reasonable. Too bad that the obvious name for this option is taken :-)

Actually we find in the Ada case that there are some warnings that are just
too specialized to be generally useful since they correspond to specific
style options that few people follow. For example, in Ada -gnatwd requires
that all dereferencing be explicit, rather than being implicit as allowed
by the language. This warning would generate false positives on nearly all
Ada code, but is useful to a very small minority that wish to follow this
particular style rule.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05 19:26 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 19:26 UTC (permalink / raw)
  To: gdr, tim; +Cc: Dautrevaux, aoliva, coola, dewar, gcc, pcarlini

<<In almost all cases, those are warnings that are useful in particular
(not uncommon) situations, but have drawbacks that prevent them from
being useful in the general case.
>>

And if this is not the case, I would consider adding them to -Wall :-)

The meaning of -Wall should be all warnings that meet the criteria that
Tim stated (very few false positives and easily silenced with an
equivalent construct). Note that my category of things that have clearly
undefined semantics should certainly meet this criterion, since

a) there should be certainly no false positives, in the sense that C code
should not contain any undefined constructs.

b) silencing them is always possible by replacing the incorrect code with
correct code :-)

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05 19:24 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 19:24 UTC (permalink / raw)
  To: gdr, tim; +Cc: Dautrevaux, aoliva, coola, dewar, gcc, pcarlini

<<That argument is flawed:  there are plenty of warning not included in
-Wall and yet actually used by people.
>>

-Wall sounds to an uninitiated chap like me that it would turn on all 
warnings. That sounds useful to me. I would be surprised to find that
there were useful warnings it did not turn on. Sure in some cases there
can be an argument to leave things out of -Wall, but I think that anything
that is clearly labeled as undefined in effect should be included in -Wall,
because really here the warning is that you are straying outside the
standard. 

Of course not all warnings are about undefined constructs, some are about
constructs that are defined, but dubious, e.g. a statement that does 
nothing at all. But for constructs that are clearly undefined, I think
-Wall should include warnings about them where possible.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* RE: a warning to implement
@ 2002-02-05 17:04 Richard Almquist
  0 siblings, 0 replies; 105+ messages in thread
From: Richard Almquist @ 2002-02-05 17:04 UTC (permalink / raw)
  To: gcc

I would like to see this warning in -Wall.

I would also ask that you consider generating an -WallXXX that includes 
everthing in -Wall plus additional warnings that are generally usefule 
but don't meet the criteria for -Wall. This would be useful in two cases.

1) A short easy to remember option that could be used periodcally to 
catch errors by turning on a bunch of additional warnings. You can do 
this now by explicitlly adding warnings but I, at least, can never 
remember that the names without going to the documentatiuon. As a 
result, I don't tend to do this as often as I should. In this case, I 
would be willing to wade through lots of warnings about things that 
aren't problems to get warnings about the things that are.

2) I could enable this option in my Makefile and then explicitlly turn 
off the warnings that cause problems.  As new warnings are added to 
-WallXXX, I would automatically get them. If they caused problems, I 
could explicitly disable them. In this case, I would only want a few 
warnings about things that aren't problems.  I, being lazy, am much more 
likely to open up the manual to explicitly disable warnings that are 
causing me trouble than I am to open the manual to look for warnings 
that -Wall doesn't turn on but might be useful.


^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05 15:55 Robert Dewar
  2002-02-05 16:58 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 15:55 UTC (permalink / raw)
  To: Dautrevaux, gdr; +Cc: aoliva, coola, dewar, gcc, pcarlini

<<Please, note that I'm not saying that GCC should not have an option to
trigger the proposed warning. I'm saying that that shouldn't be on by
default in -Wall.
>>

I disagree, this warning should be part of -Wall, since it is a clear error
with no defined meaning.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05 14:23 Robert Dewar
  2002-02-05 15:00 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 14:23 UTC (permalink / raw)
  To: Dautrevaux, gdr; +Cc: aoliva, coola, dewar, gcc, pcarlini

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 583 bytes --]

<<Now, even in the case of fundamental interger type T, since the
value of x is an inderterminate, that construct can be used to give
an explicit hint to the compiler to handle « x » in special way --
e.g. it may have a trap representation if used in a context where
there were no intervening assignment which changed x's value in a
definite way.  Pretty much, in the same of SNaNs.
>>

Seems like a horrible kludge to me. If you want to tell the compiler
something special, please do it in some direct way, and not by some
very peculiar interpretation of a meaningless construct.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05 14:12 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-05 14:12 UTC (permalink / raw)
  To: dewar, gdr; +Cc: aoliva, coola, gcc, pcarlini

<<I wanted to make if you're of the camp who considers signaling NaN a
nonsense, and now I think I have the answer.  And given that, I don't
consider your former assertion on my report has any sense or any value
(it tries to deny facts, i.e. the debate amoung the committee wasn't
about validity).
>>

Of course signalling Nan's make very good sense, I said nothing about
signallying Nan's, so I have no idea how you think you know what I think
about that issue (unless you perhaps read my book on microprocessors).

What I can't do is make any semantic connection between

   int a = a;

and signalling Nan's @!

^ permalink raw reply	[flat|nested] 105+ messages in thread
* RE: a warning to implement
@ 2002-02-05  9:31 Bernard Dautrevaux
  2002-02-05  9:44 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Bernard Dautrevaux @ 2002-02-05  9:31 UTC (permalink / raw)
  To: 'Gabriel Dos Reis', dewar; +Cc: aoliva, coola, gcc, pcarlini

> -----Original Message-----
> From: Gabriel Dos Reis [mailto:gdr@codesourcery.com]
> Sent: Tuesday, February 05, 2002 5:21 PM
> To: dewar@gnat.com
> Cc: gdr@codesourcery.com; aoliva@redhat.com; coola@ngs.ru;
> gcc@gcc.gnu.org; pcarlini@unitus.it
> Subject: Re: a warning to implement
> 
> 
> dewar@gnat.com (Robert Dewar) writes:
> 
> | <<Then you're wrong because the issue of the debate wasn't 
> whether it
> | should be valid statement; the issue was whether it could 
> be a useful
> | construct -- incidentally some wanted to make it ill-formed.
> | >>
> | 
> | Sorry, I can't imagine any useful use of this construct
> 
> That *you* can't imagine a useful use of that construct doesn't mean
> other people don't. Other people do imagine, in the same way people
> have uses of SNaNs.

There's a little difference here: SNaNs have a definite behaviour, which is
different from NaNs; however, from a language point of view, "int x = x;" is
exactly equivalent to "int x;" and really different from "int x = x0;". 

So I think it's well advised fro the compiler to warn that it doesn't do
anything with the "=x" part of the declaration, much like it warns about "if
(a = 1)" by fear it was in fact "if (a == 1)" or about "a == 0;" because it
often is a typo for "a = 0;"; in all cases there's an obvious way to avoid
the warning *in a portable way* if you really meant what was written: "int
x", "if ((a = 1) != 0)" or "(void)a;".

ALL these constructs are perfectly valid, and have perfectly correct
behaviour. We can even argue that "f() == 0;" can be used to avoid a warning
about unused return value from a call to "int f();" :-)

The fact is that in all these circumstances, GCC emit warnings. So it seems
better *for GCC* to emit a warning for "int x = x;", and to enable it for
"-Wall".

Just my .02euros

	Bernard
--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel:	+33 (0) 1 47 68 80 80
Fax:	+33 (0) 1 47 88 97 85
e-mail:	dautrevaux@microprocess.com
		b.dautrevaux@usa.net
-------------------------------------------- 

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05  5:12 Robert Dewar
  2002-02-05  8:21 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-05  5:12 UTC (permalink / raw)
  To: dewar, gdr; +Cc: aoliva, coola, gcc, pcarlini

>>Can you imagine use of signaling NaNs?

I can't even imagine what you are suggesting, sounds like nonsense to me.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-05  4:33 Robert Dewar
  2002-02-05  8:49 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-05  4:33 UTC (permalink / raw)
  To: dewar, gdr; +Cc: aoliva, coola, gcc, pcarlini

<<Then you're wrong because the issue of the debate wasn't whether it
should be valid statement; the issue was whether it could be a useful
construct -- incidentally some wanted to make it ill-formed.
>>

Sorry, I can't imagine any useful use of this construct

Yes, of course some wanted to make it ill-formed, the issue of whether
an identifier can be used in a situation like this is a standard issue
in language design.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-03 10:52 Robert Dewar
  2002-02-04 21:36 ` Gabriel Dos Reis
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-03 10:52 UTC (permalink / raw)
  To: dewar, gdr; +Cc: aoliva, coola, gcc, pcarlini

<Well, that construct have been debated to death in the C++ committee.
And given the length of the debate and the opinions expressed there I
would certainly *not* characterize it as obviously dubious.  I would
object to have it enabled by -Wall.
>
What possible useful semantic meaning can this statement have? I can see
a debate in the C++ committee as to whether it should be legal or not (that's
quite a subtle issue, and indeed could be expected to generate debate), but
I can't imagine a debate over whether it is useful or not. So I see no basis
for your objection.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-03 10:52 Robert Dewar
  0 siblings, 0 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-03 10:52 UTC (permalink / raw)
  To: coola, pcarlini; +Cc: gcc

<<Concluding the discussion on the ML, I can say that it's desirable to
have compiler emit the warning when it is run with `-Wall', and, of
course, there should be option for turning off the very warning.
>>

well I see nothing special about this warning, it is just one particular
case of accessing a variable before it has a defined value, and that is
a reasonable thing to warn about in general.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-02 18:02 Robert Dewar
  2002-02-02 18:46 ` Alexandre Oliva
  0 siblings, 1 reply; 105+ messages in thread
From: Robert Dewar @ 2002-02-02 18:02 UTC (permalink / raw)
  To: aoliva, dewar; +Cc: coola, gcc, pcarlini

>>It's not clearly bogus.  It's explicitly allowed in the Standard.

It is a self evident fact that *ALL* warnings are about things that are
allowed in the standard, or instead you would be posting an error message
so the above statement is a rather curious non-sequitur.

What is bogus about int a = a; is that it clearly has no useful meaning.
You try to establish one (turn off warnings), but there is nothing either
in the standard or in any reasonable usage that would suggest this (we
might just as well say that if you put the = sign in column 43 it turns
off warnings).

If anything deserves a warning then

  int a = a;

is in the list, since it has no sensible and useful meaning, and must surely
be a mistake.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-02 16:09 Robert Dewar
  2002-02-02 17:00 ` Alexandre Oliva
  2002-02-03 10:52 ` Gabriel Dos Reis
  0 siblings, 2 replies; 105+ messages in thread
From: Robert Dewar @ 2002-02-02 16:09 UTC (permalink / raw)
  To: aoliva, pcarlini; +Cc: coola, gcc

<<Such usage is explicitly allowed in the C and C++ Standards.  I'll
grant you it's of dubious use, but one of the legal uses I can think
for it is to avoid getting a warning about a variable being used
uninitialized when you know for sure that it is not, but the compiler
can't tell as much.  For example:
>>

Obviously this dubious use should generate a warning, and most certainly
it should be enabled by -Wall. The idea of using this to *avoid* the
warning seems absurd to me. If you want a way of turning off warnings,
implement one, but don't use a clearly bogus construct for the purpose.

^ permalink raw reply	[flat|nested] 105+ messages in thread
* Re: a warning to implement
@ 2002-02-02  2:45 Paolo Carlini
  2002-02-02 16:05 ` Alexandre Oliva
  2002-02-03 10:52 ` Andrey R. Urazov
  0 siblings, 2 replies; 105+ messages in thread
From: Paolo Carlini @ 2002-02-02  2:45 UTC (permalink / raw)
  To: coola; +Cc: gcc

>    int x = x;
>Is there any plans for implementing the feature?

Hi Andrey,
indeed it looks like gcc does'nt warn. On the other hand EDG-based compilers
emit:

"uzarov.c", line 3: warning #592: variable "x" is used before its value is set
    int x = x;
            ^

I have quickly browsed GNATS for warnings and it looks like there is'nt a PR
dealing with this. Why don't you submit one??

Cheers,
Paolo.


^ permalink raw reply	[flat|nested] 105+ messages in thread
* a warning to implement
@ 2002-02-02  1:26 Andrey R. Urazov
  0 siblings, 0 replies; 105+ messages in thread
From: Andrey R. Urazov @ 2002-02-02  1:26 UTC (permalink / raw)
  To: gcc ML

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

Hello everybody,

if I'm not mistaken, gcc never warns about incorrectness of definitions
having the following form:
    int x = x;
Is there any plans for implementing the feature?

                        Yours sincerely, Andrey Urazov
-- 
There is a vast difference between the savage and civilized man, but it
is never apparent to their wives until after breakfast.
		-- Helen Rowland
--
Saturday, February 02, 2002, 15:21:32 +0600 - Andrey R. Urazov (mailto:coola@ngs.ru)


[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

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

end of thread, other threads:[~2002-02-11 18:07 UTC | newest]

Thread overview: 105+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-05 14:14 a warning to implement Robert Dewar
2002-02-05 14:47 ` Michael Matz
2002-02-05 15:40 ` Gabriel Dos Reis
2002-02-06  4:24   ` Richard Sandiford
2002-02-06  4:51     ` Gabriel Dos Reis
2002-02-06  5:55       ` Richard Sandiford
2002-02-06  6:17         ` Gabriel Dos Reis
2002-02-06  7:56         ` Kevin Handy
2002-02-06  2:08 ` Akim Demaille
2002-02-06  7:37   ` Akim Demaille
  -- strict thread matches above, loose matches on Subject: below --
2002-02-11  7:30 Robert Dewar
2002-02-11  7:13 Robert Dewar
2002-02-11  6:53 Bernard Dautrevaux
2002-02-11  7:19 ` Alexandre Oliva
2002-02-11  7:44   ` Paolo Carlini
2002-02-11  9:25     ` Alexandre Oliva
2002-02-11 10:07       ` Joe Buck
2002-02-11 10:19         ` Alexandre Oliva
2002-02-08  9:46 Bernard Dautrevaux
2002-02-08 13:33 ` Gabriel Dos Reis
2002-02-10  7:50   ` Per Abrahamsen
2002-02-08  8:23 Robert Dewar
2002-02-08  9:09 ` Gabriel Dos Reis
2002-02-08  6:57 Bernard Dautrevaux
2002-02-08  8:21 ` Gabriel Dos Reis
2002-02-06 13:55 mike stump
2002-02-06 13:02 Robert Dewar
2002-02-07 10:51 ` Gabriel Dos Reis
2002-02-06 12:29 Robert Dewar
2002-02-06 12:35 ` Gabriel Dos Reis
2002-02-06 12:04 Robert Dewar
2002-02-06 12:22 ` Joe Buck
2002-02-06 12:32   ` Gabriel Dos Reis
2002-02-06 12:51     ` Jason Riedy
2002-02-06  9:03 Robert Dewar
2002-02-06  9:19 ` Gabriel Dos Reis
2002-02-06  8:40 Robert Dewar
2002-02-06  8:29 Robert Dewar
2002-02-06  8:29 ` Gabriel Dos Reis
2002-02-06  8:38 ` Nathan Sidwell
2002-02-06  8:50   ` Gabriel Dos Reis
2002-02-06  8:03 Robert Dewar
2002-02-06  7:51 Robert Dewar
2002-02-06  6:56 Robert Dewar
2002-02-06  8:01 ` Gabriel Dos Reis
2002-02-06  6:35 Robert Dewar
2002-02-06  2:00 Jeremy Sanders
2002-02-06  0:03 Robert Dewar
2002-02-06 10:50 ` Joe Buck
2002-02-06 11:44   ` Gabriel Dos Reis
2002-02-06 11:47     ` Joe Buck
2002-02-05 20:27 Robert Dewar
2002-02-05 20:16 Robert Dewar
2002-02-05 21:00 ` Alexandre Oliva
2002-02-06 10:51   ` Joe Buck
2002-02-06 14:04     ` Alexandre Oliva
2002-02-06 14:57       ` Joe Buck
2002-02-05 20:12 Robert Dewar
2002-02-05 20:07 Robert Dewar
2002-02-06 11:06 ` Joe Buck
2002-02-05 19:26 Robert Dewar
2002-02-05 19:24 Robert Dewar
2002-02-05 17:04 Richard Almquist
2002-02-05 15:55 Robert Dewar
2002-02-05 16:58 ` Gabriel Dos Reis
2002-02-05 14:23 Robert Dewar
2002-02-05 15:00 ` Gabriel Dos Reis
2002-02-05 14:12 Robert Dewar
2002-02-05  9:31 Bernard Dautrevaux
2002-02-05  9:44 ` Gabriel Dos Reis
2002-02-05 10:09   ` Tim Hollebeek
2002-02-05 10:42     ` Gabriel Dos Reis
2002-02-05 11:52       ` Tim Hollebeek
2002-02-05 14:48         ` Gabriel Dos Reis
2002-02-05 13:52       ` Joe Buck
2002-02-05 14:10         ` Tim Hollebeek
2002-02-05 14:29         ` Stephano Mariani
2002-02-05 14:38           ` Tim Hollebeek
2002-02-05 14:53             ` Stephano Mariani
2002-02-05 18:46               ` Joe Buck
2002-02-05 14:48         ` Gabriel Dos Reis
2002-02-05 15:03           ` Phil Edwards
2002-02-05 15:43             ` Gabriel Dos Reis
2002-02-06  9:14             ` Gerald Pfeifer
2002-02-06  9:20               ` Gabriel Dos Reis
2002-02-06  9:23               ` Phil Edwards
2002-02-06  2:12       ` Daniel Egger
2002-02-05  5:12 Robert Dewar
2002-02-05  8:21 ` Gabriel Dos Reis
2002-02-05  4:33 Robert Dewar
2002-02-05  8:49 ` Gabriel Dos Reis
2002-02-03 10:52 Robert Dewar
2002-02-04 21:36 ` Gabriel Dos Reis
2002-02-03 10:52 Robert Dewar
2002-02-02 18:02 Robert Dewar
2002-02-02 18:46 ` Alexandre Oliva
2002-02-02 16:09 Robert Dewar
2002-02-02 17:00 ` Alexandre Oliva
2002-02-03 10:52 ` Gabriel Dos Reis
2002-02-02  2:45 Paolo Carlini
2002-02-02 16:05 ` Alexandre Oliva
2002-02-03 10:52 ` Andrey R. Urazov
2002-02-03 10:52   ` Paolo Carlini
2002-02-03 10:52     ` Andrey R. Urazov
2002-02-02  1:26 Andrey R. Urazov

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 read-only IMAP folder(s) and NNTP newsgroup(s).