DW_TAG_imported_module (c++ `using namespace') has validity only in the same block in which they are stated. It works right for the compiled code but it gets defined for the whole function in DWARF.
DW_TAG_imported_module should be located in DW_TAG_lexical_block. Without the `int block_create;' declaration the whole DW_TAG_lexical_block is missing there so it should be created when needed. The testcase produces: 1 2 Tests on Fedora: compat-gcc-34-c++-3.4.6-9.x86_64 has no DW_TAG_imported_module there at all. gcc-4.3.2-3.x86_64 and gcc-4.1.2-33.x86_64 produce the output below. <1><6f>: Abbrev Number: 5 (DW_TAG_subprogram) <70> DW_AT_external : 1 <71> DW_AT_name : (indirect string, offset: 0x7f): main <75> DW_AT_decl_file : 1 <76> DW_AT_decl_line : 13 <77> DW_AT_type : <0x57> <7b> DW_AT_low_pc : 0x4005ac <83> DW_AT_high_pc : 0x4005fc <8b> DW_AT_frame_base : 0x0 (location list) <8f> DW_AT_sibling : <0xf2> <2><93>: Abbrev Number: 6 (DW_TAG_imported_module) <94> DW_AT_decl_file : 1 <95> DW_AT_decl_line : 19 <96> DW_AT_import : <0xf2> [Abbrev Number: 11 (DW_TAG_namespace)] <2><9a>: Abbrev Number: 6 (DW_TAG_imported_module) <9b> DW_AT_decl_file : 1 <9c> DW_AT_decl_line : 27 <9d> DW_AT_import : <0x10e> [Abbrev Number: 11 (DW_TAG_namespace)] <2><a1>: Abbrev Number: 7 (DW_TAG_variable) <a2> DW_AT_name : x <a4> DW_AT_decl_file : 1 <a5> DW_AT_decl_line : 15 <a6> DW_AT_type : <0x57> <aa> DW_AT_location : 2 byte block: 91 64 (DW_OP_fbreg: -28) <2><ad>: Abbrev Number: 8 (DW_TAG_lexical_block) <ae> DW_AT_low_pc : 0x4005b4 <b6> DW_AT_high_pc : 0x4005d2 <be> DW_AT_sibling : <0xd1> <3><c2>: Abbrev Number: 9 (DW_TAG_variable) <c3> DW_AT_name : (indirect string, offset: 0x32): block_create <c7> DW_AT_decl_file : 1 <c8> DW_AT_decl_line : 18 <c9> DW_AT_type : <0x57> <cd> DW_AT_location : 2 byte block: 91 68 (DW_OP_fbreg: -24) <2><d1>: Abbrev Number: 10 (DW_TAG_lexical_block) <d2> DW_AT_low_pc : 0x4005d2 <da> DW_AT_high_pc : 0x4005f0 <3><e2>: Abbrev Number: 9 (DW_TAG_variable) <e3> DW_AT_name : (indirect string, offset: 0x32): block_create <e7> DW_AT_decl_file : 1 <e8> DW_AT_decl_line : 26 <e9> DW_AT_type : <0x57> <ed> DW_AT_location : 2 byte block: 91 6c (DW_OP_fbreg: -20) -- Summary: DW_TAG_imported_module is not in its DW_TAG_lexical_block Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: minor Priority: P3 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jan dot kratochvil at redhat dot com GCC build triplet: x86_64-fedora-linux-gnu GCC host triplet: x86_64-fedora-linux-gnu GCC target triplet: x86_64-fedora-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37410