Bug 4245 – Declaring conflicting symbols in single function scope allowed

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2010-05-28T04:30:00Z
Last change time
2014-02-15T02:43:50Z
Keywords
accepts-invalid, link-failure, patch
Assigned to
nobody
Creator
rsinfu

Attachments

IDFilenameSummaryContent-TypeSize
644fix-conflict-symbols.patchPatch for dmd svn r502text/plain807

Comments

Comment #0 by rsinfu — 2010-05-28T04:30:37Z
Created attachment 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 --------------------
Comment #1 by clugdbug — 2011-02-06T13:42:58Z