namespace S { int f () { int i = 42; { extern int i; return i; } } }
generates DWARF: # Grossly simplified. <1><2d>: Abbrev Number: 2 (DW_TAG_namespace) <2e> DW_AT_name : S <2><36>: Abbrev Number: 3 (DW_TAG_subprogram) <37> DW_AT_external : 1 <38> DW_AT_name : f <3c> DW_AT_MIPS_linkage_name: (indirect string, offset: 0x49): _ZN1S1fEv <61> DW_AT_low_pc : 0x0 <69> DW_AT_high_pc : 0x13 <71> DW_AT_frame_base : 0x0 (location list) <3><75>: Abbrev Number: 7 (DW_TAG_lexical_block) <76> DW_AT_low_pc : 0x4 <7e> DW_AT_high_pc : 0x11 <4><86>: Abbrev Number: 8 (DW_TAG_variable) <87> DW_AT_name : i <8f> DW_AT_location : 2 byte block: 91 6c (DW_OP_fbreg: -20) <4><92>: Abbrev Number: 9 (DW_TAG_lexical_block) <93> DW_AT_low_pc : 0xb <9b> DW_AT_high_pc : 0x11 <2><45>: Abbrev Number: 4 (DW_TAG_variable) <46> DW_AT_name : i <4a> DW_AT_MIPS_linkage_name: (indirect string, offset: 0x40): _ZN1S1iE <52> DW_AT_external : 1 <53> DW_AT_declaration : 1 But the last DIE should have been <5><45> being in inner DW_TAG_lexical_block so that debugger would display external variable S::i in the inner block. (I have inlined the DW_AT_specification reference in the dump above.) Similar case in C works OK: int f (void) { int i = 42; { extern int i; return i; } } -- Summary: C++ external inner reference does not override outer scope Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jan dot kratochvil at redhat dot com GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43325