www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [DMD 0.118] 'switch ' crtical bug,

reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
This program below ends abnormally with the message:
C:\d\test>test.exe
Error: Switch Default test(21)

If you will add
      default: break;
in the switch everything will be fine.
Either compiler shall report "no default" either it shall not generate an 
error in runtime.

Andrew.

=== test.d =================================================
import std.stdio;

enum DRAW: uint // drawChars flags
{
      LEFT = 0x0,
      CENTER = 0x1,
      RIGHT = 0x2,

      TOP =   0x00,
      MIDDLE =  0x10,
      BOTTOM =  0x20,

      END_ELLIPSIS  = 0x100,
      PATH_ELLIPSIS = 0x200,
      WORD_ELLIPSIS = 0x300,
}

int main(char[][] args)
{
  uint f = 0x10;
  switch( f & 0xF00 )
  {
  case DRAW.END_ELLIPSIS:
    writef("END_ELLIPSIS\n"); break;
  case DRAW.PATH_ELLIPSIS:
    writef("PATH_ELLIPSIS\n"); break;
  case DRAW.WORD_ELLIPSIS:
    writef("WORD_ELLIPSIS\n"); break;
  }
  return 0;
}
Mar 14 2005
next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Andrew Fedoniouk wrote:

 This program below ends abnormally with the message:
 C:\d\test>test.exe
 Error: Switch Default test(21)

It disappears in -release mode, though...
 If you will add
       default: break;
 in the switch everything will be fine.

Yes, and even the (-w) warning goes away.
 Either compiler shall report "no default" either it shall not generate an 
 error in runtime.

This is a known behaviour, though (not a bug). See also: http://www.prowiki.org/wiki4d/wiki.cgi?ShortFrequentAnswers --anders
Mar 14 2005
parent "Andrew Fedoniouk" <news terrainformatica.com> writes:
Thanks Anders.

I guess we should add there "no return value" issue also.
Like:
Rect place(Rect r)
{
   _place = r;
}
will also generate an exception in debug but will compile fine.

Andrew.


"Anders F Björklund" <afb algonet.se> wrote in message 
news:d154md$2md5$3 digitaldaemon.com...
 Andrew Fedoniouk wrote:

 This program below ends abnormally with the message:
 C:\d\test>test.exe
 Error: Switch Default test(21)

It disappears in -release mode, though...
 If you will add
       default: break;
 in the switch everything will be fine.

Yes, and even the (-w) warning goes away.
 Either compiler shall report "no default" either it shall not generate an 
 error in runtime.

This is a known behaviour, though (not a bug). See also: http://www.prowiki.org/wiki4d/wiki.cgi?ShortFrequentAnswers --anders

Mar 14 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Andrew Fedoniouk" <news terrainformatica.com> wrote in message
news:d1549k$2o21$1 digitaldaemon.com...
 This program below ends abnormally with the message:
 C:\d\test>test.exe
 Error: Switch Default test(21)

Yes, that's expected behavior in D. Unlike C, there is no implied default: break; inserted in a switch statement without an explicit break. D will insert an implicit default: throw new SwitchError();
Mar 14 2005
parent reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
 Yes, that's expected behavior in D. Unlike C, there is no implied
    default: break;
 inserted in a switch statement without an explicit break. D will insert an
 implicit
    default: throw new SwitchError();

Thanks, Walter. My assumption was that command line: dmd.exe test.d will produce release version. That was wrong (why, btw?). It produces debug version and so I am getting new SwitchError(); And only if I explicitly say "-release" then it disappears. Andrew.
Mar 14 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Mon, 14 Mar 2005 19:03:46 -0800, Andrew Fedoniouk wrote:


[snip]
 
 My assumption was that command line:
 
        dmd.exe test.d
 
 will produce release version. That was wrong (why, btw?).

My guess is that nearly all compiles are done to create an edition of the application that is about to undergo testing, as opposed to an edition that is destined for an end-user. (Except, of course, if you're MS :D ) So, one would only use the -release option to create the edition that will be used for User Acceptance Testing or similar, and that will be used to create shippable copies of the application. -- Derek Parnell Melbourne, Australia http://www.dsource.org/projects/build/ http://www.prowiki.org/wiki4d/wiki.cgi?FrontPage 15/03/2005 2:33:08 PM
Mar 14 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"Derek Parnell" <derek psych.ward> wrote in message
news:1gfotxu9j0id.g73pfkq3o5f2.dlg 40tude.net...
 My guess is that nearly all compiles are done to create an edition of the
 application that is about to undergo testing, as opposed to an edition

 is destined for an end-user. (Except, of course, if you're MS :D )

 So, one would only use the -release option to create the edition that will
 be used for User Acceptance Testing or similar, and that will be used to
 create shippable copies of the application.

Yes.
Mar 14 2005
parent reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
"Walter" <newshound digitalmars.com> wrote in message 
news:d15ljm$5s6$1 digitaldaemon.com...
 "Derek Parnell" <derek psych.ward> wrote in message
 news:1gfotxu9j0id.g73pfkq3o5f2.dlg 40tude.net...
 My guess is that nearly all compiles are done to create an edition of the
 application that is about to undergo testing, as opposed to an edition

 is destined for an end-user. (Except, of course, if you're MS :D )

 So, one would only use the -release option to create the edition that 
 will
 be used for User Acceptance Testing or similar, and that will be used to
 create shippable copies of the application.

Yes.

Sure :) I guess that definition of compiler option should state: -debug compile in debug code (default option) (default option) - is my addon.... If you don't mind to catch someone else on this....
Mar 14 2005
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Andrew Fedoniouk wrote:

 Sure :) I guess that definition of compiler option should state:
 
 -debug
     compile in debug code (default option)
 
 (default option) - is my addon....
 
 If you don't mind to catch someone else on this....

The thing is that -debug and -release are *unrelated* options. -debug activates a "version" (i.e. the debug { } code areas), while -release removes contracts and switch/bounds checking Then there are also the -g and -O flags too, which are also semi-related but totally different. And of course -inline... And yes, it's a little confusing (at least at first) --anders
Mar 14 2005