[Bug c++/10591] PCH breaks anonymous namespaces

geoffk at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Apr 7 00:55:00 GMT 2006



------- Comment #23 from geoffk at gcc dot gnu dot org  2006-04-07 00:55 -------
(In reply to comment #22)
> The PCH problem with get_file_function_name is independent of the question of
> giving anonymous namespace members internal linkage.  We still need to give
> them distinct names; we are giving up on address comparison of type_infos
> because of problems with plugins.

If you're giving up address comparison on type_info, you still have to find a
way where two typeinfo objects with the same C++ name can be different, due to
this example:

A shared object contains

class A { };
class B __attribute__((visibility("hidden"))) : class A { };
void f () { throw new B(); }

A main program contains:

class A { };
extern void f();
class B __attribute__((visibility("hidden"))) { int x; };  // not an A
int main() {
  try {
    f();
  } catch (B * p) {
    abort();
  } catch (A * p) {
    exit (0);
  }
  abort();
}

This program should not abort, because the 'B' in the main program is not the
same as the 'B' in the dylib.

My suggestion would be to include &__dso_handle in the typeinfo for objects
with hidden visibility, and also compare that.

Now, if you're doing this for visibility, you can also do it for anonymous
namespaces.  Just find any address in the translation unit that contains the
anonymous namespace (hey, how about the address of the typeinfo itself?), and
consistently include that address in the typeinfo, and compare that.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10591



More information about the Gcc-bugs mailing list