Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!unmvax!tut.cis.ohio-state.edu!cica!iuvax!mailrus!csd4.milw.wisc.edu!srcsip!nic.MR.NET!ns!hughes From: hughes@ns.network.com (Jim Hughes x1676) Newsgroups: comp.lang.c++ Subject: Re: default argument bug in 1.2! Message-ID: <1505@ns.network.com> Date: 24 Jul 89 14:22:12 GMT References: <503@gill.UUCP> <6409@columbia.edu> Sender: hughes@ns.network.com (Jim Hughes x1676) Reply-To: hughes@ns.UUCP (Jim Hughes x1676) Organization: Network Systems Corporation Lines: 53 In article <6409@columbia.edu> kearns@read.UUCP (Steve Kearns) writes: > >Is there a workaround for the following bug? > >When I declare a member function to have a default constant argument, >such as : > >class bar { > foo(int joe, int bill = -1); >}; > > >Then the definition of foo usually contains a test like the following: > > if (bill == -1) > { ...do this...} > else > { ...do that...} > >The bug is that 1.2 seems to optimize out the if (bill == ..) test >and include, in this case, only the first branch of the "if". >It seems to treat the "int bill = -1" declaration as if I was initializing >a local variable. > >Does anyone know any workarounds? >-steve I have compiled a test case, and found that this does not seem to be an error as simple as you have stated. The following complete program works correctly and prints "bill != -1". --------------------------- //test.c #include class bar{ public: void foo(int joe, int bill= -1); }; void bar.foo(int joe, int bill= -1) { if (bill == -1) printf("bill == -1\n"); else printf("bill != -1\n"); } main() { bar b; b.foo(23,24); } ---------------------------- Jim hughes@network.com