Jump to page: 1 25  
Page
Thread overview
Bug or plain misunderstanding?
Feb 05, 2006
Bob W
Feb 05, 2006
Derek Parnell
Feb 05, 2006
Walter Bright
Feb 05, 2006
Derek Parnell
Feb 05, 2006
Matthew
Feb 06, 2006
Matthew
Feb 06, 2006
Walter Bright
Feb 07, 2006
Matthew
Feb 07, 2006
Sean Kelly
Feb 07, 2006
Matthew
Feb 07, 2006
Sean Kelly
Feb 07, 2006
Regan Heath
Feb 07, 2006
Matthew
Feb 07, 2006
Walter Bright
Feb 07, 2006
Matthew
Feb 07, 2006
Walter Bright
Feb 08, 2006
Matthew
Feb 08, 2006
Derek Parnell
Feb 07, 2006
Walter Bright
Feb 07, 2006
Matthew
Feb 07, 2006
Walter Bright
Feb 07, 2006
Matthew
Feb 07, 2006
Don Clugston
Feb 07, 2006
Matthew
Feb 07, 2006
Sean Kelly
Feb 07, 2006
Walter Bright
Feb 08, 2006
Matthew
Feb 08, 2006
Regan Heath
Feb 05, 2006
Walter Bright
Feb 05, 2006
Derek Parnell
Feb 06, 2006
Walter Bright
Feb 06, 2006
Sean Kelly
Feb 06, 2006
John Demme
Feb 06, 2006
Walter Bright
Feb 07, 2006
John Demme
Feb 07, 2006
Walter Bright
Feb 07, 2006
Bob W
Feb 13, 2006
Walter Bright
Feb 08, 2006
Derek Parnell
Feb 07, 2006
Bruno Medeiros
Feb 07, 2006
Walter Bright
Feb 08, 2006
Bruno Medeiros
Feb 08, 2006
Bruno Medeiros
Feb 06, 2006
Bob W
February 05, 2006
Hi,

after a couple of months of absence from D and
this forum, I am officially still busy reducing
the backlog of work I was accumulating due to
some unforeseen events. So please don't tell
anybody I was here!

D seems to be thriving and is probably right on
track - my old programs still compile with 0.145.

However, I have noticed one little dmd behaviour,
which I was not expecting:

When warnings are enabled with '-w' and if
the program contains unreachable code (e.g.
due to a casual insertion of a return statement
for debugging purposes), the compiler will
issue the proper warning but it will not
generate any code (i.e. exe file).

Should I understand the compiler usage info
"-w ... enable warnings" as
"-w ... enable warnings and treat them as errors"
or is this compiler behaviour unintentional?


For further clarification I have included this
little demo program:



///////////////////////////////////////////////////////////
//
// Possible bug in dmd 0.145:
//
// When attempting to disable a portion of code with an
// early return statement, dmd properly issues a warning
// if the program is compiled with '-w'.
// But it apparently treats the warning as an error, so
// it does not generate any code. If '-w' is omitted,
// everything works as expected.
//
///////////////////////////////////////////////////////////


import std.stdio;


int main() {
  writefln();
  writefln("Sample program demonstrating '-w' bug:");
  writefln();

/*
  // Uncomment this section and compile program with '-w'
  // to experience warning without code generation.
  // (You might want to erase an eventually existing old
  // .exe file first in order to verify this.)

  writefln("Attempt to stop program after this message.");
  return(0);  // <<<< stop the nonsense here!
*/

  writefln();
  transfertoSCO();
  installMSDOS();
  emailCongrats();
  return(0);
}


void transfertoSCO() {
  writefln("    Donating $100 000 to SCO Group Inc ...");
  /* sophisticated code goes here */
  writefln("... debiting Mr. Torvalds' bank account ...");
  /* sophisticated code goes here */
  writefln("... transaction successfully completed.");
  writefln();  writefln();
}

void installMSDOS() {
  writefln("    Erasing Windows XP and/or Linux ...");
  /* sophisticated code goes here */
  writefln("... installing MSDOS 2.01 ...");
  /* sophisticated code goes here */
  writefln("... MSDOS successfully installed.");
  writefln();  writefln();
}

void emailCongrats() {
  writefln("    Preparing email to GWB ...");
  /* sophisticated code goes here */
  writefln("... 'congrats to success finding WMD' ...");
  /* sophisticated code goes here */
  writefln("... attempting to send email ...");
  writefln("... reply from operating system:");
  writefln("    what is 'email' ???");
  writefln("    Abort, Retry, Fail?");
  writefln();  writefln();
}




February 05, 2006
On Mon, 06 Feb 2006 06:38:50 +1100, Bob W <nospam@aol.com> wrote:

> Hi,
>
> after a couple of months of absence from D and
> this forum, I am officially still busy reducing
> the backlog of work I was accumulating due to
> some unforeseen events. So please don't tell
> anybody I was here!
>
> D seems to be thriving and is probably right on
> track - my old programs still compile with 0.145.
>
> However, I have noticed one little dmd behaviour,
> which I was not expecting:
>
> When warnings are enabled with '-w' and if
> the program contains unreachable code (e.g.
> due to a casual insertion of a return statement
> for debugging purposes), the compiler will
> issue the proper warning but it will not
> generate any code (i.e. exe file).
>
> Should I understand the compiler usage info
> "-w ... enable warnings" as
> "-w ... enable warnings and treat them as errors"
> or is this compiler behaviour unintentional?
>

As far as Walter is concerned, a 'warning' is really an error too. So yes, DMD will display warnings but treat them as errors such that the compiler doesn't generate code.

-- 
Derek Parnell
Melbourne, Australia
February 05, 2006
"Derek Parnell" <derek@psych.ward> wrote in message news:op.s4imylg86b8z09@ginger.vic.bigpond.net.au...
> As far as Walter is concerned, a 'warning' is really an error too. So yes, DMD will display warnings but treat them as errors such that the compiler doesn't generate code.

That's right. If the programmer cares about warnings, he'll want them to be treated as errors. Otherwise, the warning message could scroll up and all too easilly be overlooked.


February 05, 2006
On Mon, 06 Feb 2006 07:34:37 +1100, Walter Bright <newshound@digitalmars.com> wrote:

>
> "Derek Parnell" <derek@psych.ward> wrote in message
> news:op.s4imylg86b8z09@ginger.vic.bigpond.net.au...
>> As far as Walter is concerned, a 'warning' is really an error too. So yes,
>> DMD will display warnings but treat them as errors such that the compiler
>> doesn't generate code.
>
> That's right. If the programmer cares about warnings, he'll want them to be
> treated as errors. Otherwise, the warning message could scroll up and all
> too easilly be overlooked.

However, not everyone thinks like Walter. I, for example, regard a warning as different from an error. A warning tells me about a issue that the compiler has had to make an assumption in order to generate code. An error tells me about an issue that the compiler has decided that there are no assumptions that can be made and thus it can't generate valid code.

A warning alerts me to the fact that the compiler has made an assumption on my behalf and thus I might want to do something to avoid a 'wrong' compiler assumption. These assumptions are not, per se, errors. Thus if "-w" is not used the compiler generates code and so I can't see why the compiler still can't generate code when "-w" is used. All I want to know is where the compiler has assumed things I didn't actually intend.

-- 
Derek Parnell
Melbourne, Australia
February 05, 2006
"Derek Parnell" <derek@psych.ward> wrote in message news:op.s4iq6vrk6b8z09@ginger.vic.bigpond.net.au...
> On Mon, 06 Feb 2006 07:34:37 +1100, Walter Bright <newshound@digitalmars.com> wrote:
>
> >
> > "Derek Parnell" <derek@psych.ward> wrote in message news:op.s4imylg86b8z09@ginger.vic.bigpond.net.au...
> >> As far as Walter is concerned, a 'warning' is really an error too. So
> >> yes,
> >> DMD will display warnings but treat them as errors such that the
> >> compiler
> >> doesn't generate code.
> >
> > That's right. If the programmer cares about warnings, he'll want them to
> > be
> > treated as errors. Otherwise, the warning message could scroll up and
all
> > too easilly be overlooked.
>
> However, not everyone thinks like Walter. I, for example, regard a warning as different from an error. A warning tells me about a issue that the compiler has had to make an assumption in order to generate code. An error tells me about an issue that the compiler has decided that there are no assumptions that can be made and thus it can't generate valid code.
>
> A warning alerts me to the fact that the compiler has made an assumption on my behalf and thus I might want to do something to avoid a 'wrong' compiler assumption. These assumptions are not, per se, errors. Thus if "-w" is not used the compiler generates code and so I can't see why the compiler still can't generate code when "-w" is used. All I want to know is where the compiler has assumed things I didn't actually intend.

Pretty much agree. There should be a complementary "warnings as errors" flag as well.

Walter's sentiments are agreeable when one is dealing with production builds, under which only a fool would not invoke "warnings as errors", but when experimenting, or working on something new, or inserting returns for debugging (something Walter strongly advocates, btw), or myriad other "messing around" purposes, it's going to be more hindrance than help.

Sorry to start off the week with an insult, but this is another instance where Walter's personal prejudices impact negatively on the "sensibleness" of the language/compiler.





February 05, 2006
"Derek Parnell" <derek@psych.ward> wrote in message news:op.s4iq6vrk6b8z09@ginger.vic.bigpond.net.au...
> On Mon, 06 Feb 2006 07:34:37 +1100, Walter Bright <newshound@digitalmars.com> wrote:
>> That's right. If the programmer cares about warnings, he'll want them to
>> be
>> treated as errors. Otherwise, the warning message could scroll up and all
>> too easilly be overlooked.
>
> However, not everyone thinks like Walter. I, for example, regard a warning as different from an error. A warning tells me about a issue that the compiler has had to make an assumption in order to generate code. An error tells me about an issue that the compiler has decided that there are no assumptions that can be made and thus it can't generate valid code.
>
> A warning alerts me to the fact that the compiler has made an assumption on my behalf and thus I might want to do something to avoid a 'wrong' compiler assumption. These assumptions are not, per se, errors. Thus if "-w" is not used the compiler generates code and so I can't see why the compiler still can't generate code when "-w" is used. All I want to know is where the compiler has assumed things I didn't actually intend.

The assumption is that people who enable warnings by throwing "-w" care about any generated warnings and want to fix them before proceeding. If the warnings are irrelevant to them, they can just not throw "-w" and the code will compile successfully.

I don't see a practical reason for deliberately throwing "-w" but not wanting to deal with the results. I know this isn't how C++ compilers deal with warnings by default, but my experience is that people who care about warnings from their C++ compiler also throw the switch "treat warnings as errors" for the express purpose of not missing them.

Think of them as "optional errors" instead of warnings <g>.


February 05, 2006
On Sun, 5 Feb 2006 13:51:55 -0800, Walter Bright wrote:

> "Derek Parnell" <derek@psych.ward> wrote in message news:op.s4iq6vrk6b8z09@ginger.vic.bigpond.net.au...
>> On Mon, 06 Feb 2006 07:34:37 +1100, Walter Bright <newshound@digitalmars.com> wrote:
>>> That's right. If the programmer cares about warnings, he'll want them to
>>> be
>>> treated as errors. Otherwise, the warning message could scroll up and all
>>> too easilly be overlooked.
>>
>> However, not everyone thinks like Walter. I, for example, regard a warning as different from an error. A warning tells me about a issue that the compiler has had to make an assumption in order to generate code. An error tells me about an issue that the compiler has decided that there are no assumptions that can be made and thus it can't generate valid code.
>>
>> A warning alerts me to the fact that the compiler has made an assumption on my behalf and thus I might want to do something to avoid a 'wrong' compiler assumption. These assumptions are not, per se, errors. Thus if "-w" is not used the compiler generates code and so I can't see why the compiler still can't generate code when "-w" is used. All I want to know is where the compiler has assumed things I didn't actually intend.
> 
> The assumption is that people who enable warnings by throwing "-w" care about any generated warnings and want to fix them before proceeding. If the warnings are irrelevant to them, they can just not throw "-w" and the code will compile successfully.

I really do understand your point of view here. The current dmd behaviour is not a problem for me as I use the "-w" switch to highlight the areas I want to remove the compiler's assumptions, *prior* to running tests of the executable. However, I can also see that some other people might really want to do both - see where the assumptions are *and* allow the compiler to make those assumptions.

> I don't see a practical reason for deliberately throwing "-w" but not wanting to deal with the results.

That maybe the case, but the fact that you "don't see a practical reason" does not necessarily rule out the possibility that other people might truly see a valid reason. One has to accept that some other people's thinking is valid, though thoroughly weird when seen from one's own point of view.

> I know this isn't how C++ compilers deal with warnings by default, but my experience is that people who care about warnings from their C++ compiler also throw the switch "treat warnings as errors" for the express purpose of not missing them.

I quite sure that other people can also quote from their C++ experience
with instances to the contrary - so what does that prove? Only that not
everyone thinks the same as you do.

> Think of them as "optional errors" instead of warnings <g>.

Like I say, the current behaviour is not a problem for me. For example, given the example of the OP, I would do this instead ...

int main() {
  writefln();
  writefln("Sample program demonstrating '-w' bug:");
  writefln();

  debug
  {
  writefln("Attempt to stop program after this message.");
  return(0);
  }
  else {
  writefln();
  transfertoSCO();
  installMSDOS();
  emailCongrats();
  return(0);
  }

}

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
6/02/2006 10:04:16 AM
February 06, 2006
"Walter Bright" <newshound@digitalmars.com> wrote in message news:ds5p5i$1e2j$1@digitaldaemon.com...
>
> "Derek Parnell" <derek@psych.ward> wrote in message news:op.s4imylg86b8z09@ginger.vic.bigpond.net.au...
>> As far as Walter is concerned, a 'warning' is really an error too. So yes, DMD will display warnings but treat them as errors such that the compiler doesn't generate code.
>
> That's right. If the programmer cares about warnings, he'll want them to be treated as errors. Otherwise, the warning message could scroll up and all too easilly be overlooked.
>

That is cool with me. I just needed to know.

However, there is a philosophical side to it:

What sense does it make to allow a specific program
to compile without trouble if one ever forgets to turn
on warnings, if the same programs would fail to
compile otherwise?

If punishment for warnings is the same as that
for errors, why would you still call them warnings?
Correct me if I am wrong, but my perception is
that "warnings in D are morally less severe errors
but still inexcusable if enabled to be caught",
right?

Whatever - may I just suggest the following
modification to the usage screen of dmd?

------------- From ----------------

Usage:
  dmd files.d ... { -switch }
................
  -version=ident  compile in version code identified by ident
  -w             enable warnings

-------------- change to -------------

Usage:
  dmd files.d ... { -switch }
................
  -version=ident  compile in version code identified by ident
  -w             enable warnings and treat them as errors



February 06, 2006
"Derek Parnell" <derek@psych.ward> wrote in message news:t4q17cntutnl$.1tpdi4h6n15md$.dlg@40tude.net...
> That maybe the case, but the fact that you "don't see a practical reason"
> does not necessarily rule out the possibility that other people might
> truly
> see a valid reason. One has to accept that some other people's thinking is
> valid, though thoroughly weird when seen from one's own point of view.

I have many years of experience with warnings, and none of it finds any use for warnings that do not stop the compiler. If someone believes there is a valid reason, they need to present a very convincing case.

Just because C compilers do it that way by default is not a compelling reason, since a lot of C compiler defaults are that way in order to not break existing makefiles rather than them being a good idea.

> I quite sure that other people can also quote from their C++ experience with instances to the contrary -

If there's a compelling case to be made, bring it on <g>.

> so what does that prove? Only that not everyone thinks the same as you do.

Of course. But at the end of the day I have to make some decisions about how D will and will not work.


February 06, 2006
Walter Bright wrote:
> "Derek Parnell" <derek@psych.ward> wrote in message news:t4q17cntutnl$.1tpdi4h6n15md$.dlg@40tude.net...
>> That maybe the case, but the fact that you "don't see a practical reason"
>> does not necessarily rule out the possibility that other people might truly
>> see a valid reason. One has to accept that some other people's thinking is
>> valid, though thoroughly weird when seen from one's own point of view.
> 
> I have many years of experience with warnings, and none of it finds any use for warnings that do not stop the compiler. If someone believes there is a valid reason, they need to present a very convincing case.

So long as the warnings can be disabled, I'm fine with this behavior.  I may not consider all warnings important (Visual C++ tends to warn about a handful of things that have nothing to do with code correctness), but for those I do, I typically want to fix them before proceeding.


Sean
« First   ‹ Prev
1 2 3 4 5