www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - DMD D Compiler warnings

reply Marcio Faustino <Marcio_member pathlink.com> writes:
Hi all,

I have this simple program:

int main()
{
int x;

{
int x;      // illegal, x is multiply defined in function scope
}

return 0;
}

And according to the lexical for statements
(http://www.digitalmars.com/d/statement.html) it should be illegal to re-define
x. But, the DMD D Compiler (using version 0.144) doesn't warn anything about it.
I'm compiling the program as: dmd main.d -w

Any suggestions?

Thanks,

Marcio Faustino
Jan 26 2006
next sibling parent Don Clugston <dac nospam.com.au> writes:
Marcio Faustino wrote:
 Hi all,
 
 I have this simple program:
 
 int main()
 {
 int x;
 
 {
 int x;      // illegal, x is multiply defined in function scope
 }
 
 return 0;
 }
 
 And according to the lexical for statements
 (http://www.digitalmars.com/d/statement.html) it should be illegal to re-define
 x. But, the DMD D Compiler (using version 0.144) doesn't warn anything about
it.
 I'm compiling the program as: dmd main.d -w
 
 Any suggestions?
 
 Thanks,
 
 Marcio Faustino
Confirmed. Definitely a bug. Actually this should be an error, not a warning. Looking at http://www.digitalmars.com/d/statement.html, the examples func2() and func3() compile without any complaint. This is probably a regression, I'm sure it used to work. Report it in digitalmars.d.bugs.
Jan 26 2006
prev sibling next sibling parent "Derek Parnell" <derek psych.ward> writes:
On Thu, 26 Jan 2006 20:51:15 +1100, Marcio Faustino  
<Marcio_member pathlink.com> wrote:

 Hi all,

 I have this simple program:

 int main()
 {
 int x;

 {
 int x;      // illegal, x is multiply defined in function scope
 }

 return 0;
 }

 And according to the lexical for statements
 (http://www.digitalmars.com/d/statement.html) it should be illegal to  
 re-define
 x. But, the DMD D Compiler (using version 0.144) doesn't warn anything  
 about it.
 I'm compiling the program as: dmd main.d -w

 Any suggestions?
I believe this is a mistake in the documentation. A block begins a new scope. -- Derek Parnell Melbourne, Australia
Jan 29 2006
prev sibling parent Bruno Medeiros <daiphoenixNO SPAMlycos.com> writes:
Marcio Faustino wrote:
 Hi all,
 
 I have this simple program:
 
 int main()
 {
 int x;
 
 {
 int x;      // illegal, x is multiply defined in function scope
 }
 
 return 0;
 }
 
 And according to the lexical for statements
 (http://www.digitalmars.com/d/statement.html) it should be illegal to re-define
 x. But, the DMD D Compiler (using version 0.144) doesn't warn anything about
it.
 I'm compiling the program as: dmd main.d -w
 
 Any suggestions?
 
 Thanks,
 
 Marcio Faustino
Recall this: "Entity name shadowing: valid or not ?" http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.learn/1979 Last word I got from Walter ( http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.announce/1872 ) he himself wasn't sure about those. I think the func2 case should be allowed (that is, name shadowing with a new scope). -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
Jan 31 2006