Changed resolution of anonymous namespace extern from gcc 3.4.2 to 4.1.0

Earl Chew earl_chew@agilent.com
Thu Sep 18 12:01:00 GMT 2008


Earl Chew wrote:
> I can't make up my mind whether the new behaviour is incorrect,
> or whether the old behaviour should never have been supported.

I'm pretty certain this is a defect because I can construct a
program that should work, but doesn't.

In any case, I've discovered that this was an aberration of
4.1.0, and does not appear in later versions.



Consider foo.cpp:

     namespace { extern const char f[]; }
     namespace { const char f[] = "abc"; }

     const char* g = f;





Expect variable g to be global, but f to have non-global scope.

3.4.2 Pass
4.1.0 Fail
4.1.1 Pass
4.1.2 Fail


************************ 4.1.2 ***************************************
************************ PASS  ***************************************

         .file   "foo.cpp"
.globl g
         .data
         .align 8
         .type   g, @object
         .size   g, 8
g:
         .quad   _ZN36_GLOBAL__N_foo.cpp_00000000_2B2B2FAE1fE
         .section        .rodata
         .type   _ZN36_GLOBAL__N_foo.cpp_00000000_2B2B2FAE1fE, @object
         .size   _ZN36_GLOBAL__N_foo.cpp_00000000_2B2B2FAE1fE, 4
_ZN36_GLOBAL__N_foo.cpp_00000000_2B2B2FAE1fE:
         .string "abc"
         .ident  "GCC: (GNU) 4.1.2 20070626 (Red Hat 4.1.2-14)"
         .section        .note.GNU-stack,"",@progbits


************************ 4.1.1 ***************************************
************************ PASS  ***************************************

         .file   "foo.cpp"
.globl g
         .data
         .align 4
         .type   g, @object
         .size   g, 4
g:
         .long   _ZN36_GLOBAL__N_foo.cpp_00000000_8E53D9441fE
         .section        .rodata
         .type   _ZN36_GLOBAL__N_foo.cpp_00000000_8E53D9441fE, @object
         .size   _ZN36_GLOBAL__N_foo.cpp_00000000_8E53D9441fE, 4
_ZN36_GLOBAL__N_foo.cpp_00000000_8E53D9441fE:
         .string "abc"
         .ident  "GCC: (GNU) 4.1.1 20070105 (Red Hat 4.1.1-51)"
         .section        .note.GNU-stack,"",@progbits


************************ 4.1.0 ***************************************
************************ FAIL  ***************************************

         .file   "foo.cpp"
.globl _ZN36_GLOBAL__N_foo.cpp_00000000_54D6CB4D1fE
         .section        .rodata
         .type   _ZN36_GLOBAL__N_foo.cpp_00000000_54D6CB4D1fE, @object
         .size   _ZN36_GLOBAL__N_foo.cpp_00000000_54D6CB4D1fE, 4
_ZN36_GLOBAL__N_foo.cpp_00000000_54D6CB4D1fE:
         .string "abc"
.globl g
         .data
         .align 4
         .type   g, @object
         .size   g, 4
g:
         .long   _ZN36_GLOBAL__N_foo.cpp_00000000_54D6CB4D1fE
         .ident  "GCC: (GNU) 4.1.0"
         .section        .note.GNU-stack,"",@progbits


************************ 3.4.2 ***************************************
************************ PASS  ***************************************

         .file   "foo.cpp"
         .globl _ZN36_GLOBAL__N_foo_cpp_00000000_4C2300AC1fE
         .section        .rodata
         .align 2
         .type   _ZN36_GLOBAL__N_foo_cpp_00000000_4C2300AC1fE, @object
         .size   _ZN36_GLOBAL__N_foo_cpp_00000000_4C2300AC1fE, 4
_ZN36_GLOBAL__N_foo_cpp_00000000_4C2300AC1fE:
         .string "abc"
         .globl g
         .section        ".data"
         .align 2
         .type   g, @object
         .size   g, 4
g:
         .long   _ZN36_GLOBAL__N_foo_cpp_00000000_4C2300AC1fE
         .ident  "GCC: (GNU) 3.4.2 (mingw-special)"




More information about the Gcc mailing list