www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4245] New: Declaring conflicting symbols in single function scope allowed

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4245

           Summary: Declaring conflicting symbols in single function scope
                    allowed
           Product: D
           Version: 2.041
          Platform: x86
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, link-failure, patch
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rsinfu gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu gmail.com> 2010-05-28 04:30:37 PDT
---
Created an attachment (id=644)
Patch for dmd svn r502

This code is correctly rejected:
-------------------- test1.d
void main()
{
    {  void foo() {}  }
    {  void foo() {}  }
}
--------------------
% dmd test1
test1.d(4): Error: declaration foo is already defined in another scope in main
--------------------

However the following is accepted and link fails due to the name conflict.
-------------------- test2.d
void main()
{
    { typedef    int T = 1;   T v; assert(v   == 1); }
    { struct T { int a = 2; } T v; assert(v.a == 2); }
    { union  T { int a = 3; } T v; assert(v.a == 3); }
    { class  T { int a = 4; } T v; assert(v.a == 4); }
    { enum   T {     a = 5  } T v; assert(v   == 5); }
}
--------------------
% dmd test2
test2.o(.rodata+0x14): multiple definition of `_Dmain1T6__initZ'
test2.o(.rodata+0x10): first defined here
test2.o(.rodata+0x18): multiple definition of `_Dmain1T6__initZ'
test2.o(.rodata+0x10): first defined here
test2.o(.rodata+0x20): multiple definition of `_Dmain1T6__initZ'
test2.o(.rodata+0x10): first defined here
--------------------


The attached patch fixes the problem by rejecting such cases.
--------------------
% dmd test2
test2.d(4): Error: declaration T is already defined in another scope in main
test2.d(5): Error: declaration T is already defined in another scope in main
test2.d(6): Error: declaration T is already defined in another scope in main
test2.d(7): Error: declaration T is already defined in another scope in main
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 28 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4245


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED


--- Comment #1 from Don <clugdbug yahoo.com.au> 2011-02-06 13:42:58 PST ---
Fixed
https://github.com/D-Programming-Language/dmd/commit/7844aae22acfca99a7e4c70c4900d8ef21a8d8c1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011