Thread overview
DMD D Compiler warnings
Jan 26, 2006
Marcio Faustino
Jan 26, 2006
Don Clugston
Jan 29, 2006
Derek Parnell
Jan 31, 2006
Bruno Medeiros
January 26, 2006
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
January 26, 2006
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.
January 29, 2006
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
January 31, 2006
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."