2007-12-10 Jakub Jelinek PR c++/34238 * decl2.c (cp_write_global_declarations): Revert 2007-11-22 change. * g++.dg/ext/visibility/anon7.C: Add xfail. * g++.dg/ext/visibility/anon9.C: New test. * g++.dg/ext/visibility/anon10.C: New test. --- gcc/cp/decl2.c.jj 2007-12-09 22:25:40.000000000 +0100 +++ gcc/cp/decl2.c 2007-12-09 22:29:59.000000000 +0100 @@ -3366,21 +3366,7 @@ cp_write_global_declarations (void) /* If this static data member is needed, provide it to the back end. */ if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl)) - { - /* Error on - namespace { struct A { static int i; }; } - int foo () { return A::i; } - without A::i definition (which can't be defined in - a different CU because of the anonymous namespace). - Don't do this if DECL_INITIAL is set, because for - namespace { struct A { static const int i = 4; } }; - decl_needed_p won't reliably detect whether it was - really needed. */ - if (DECL_IN_AGGR_P (decl) && DECL_INITIAL (decl) == NULL_TREE) - error ("%Jstatic data member %qD used, but not defined", - decl, decl); - DECL_EXTERNAL (decl) = 0; - } + DECL_EXTERNAL (decl) = 0; } if (VEC_length (tree, pending_statics) != 0 && wrapup_global_declarations (VEC_address (tree, pending_statics), --- gcc/testsuite/g++.dg/ext/visibility/anon7.C.jj 2007-11-20 19:12:40.000000000 +0100 +++ gcc/testsuite/g++.dg/ext/visibility/anon7.C 2007-12-09 20:54:27.000000000 +0100 @@ -5,7 +5,7 @@ namespace { struct A { static int bar (); - static int i; // { dg-error "used, but not defined" } + static int i; // { dg-error "used, but not defined" "" { xfail *-*-* } } static int j; static int k; static int l; --- gcc/testsuite/g++.dg/ext/visibility/anon9.C.jj 2007-12-04 20:44:19.000000000 +0100 +++ gcc/testsuite/g++.dg/ext/visibility/anon9.C 2007-12-04 20:44:19.000000000 +0100 @@ -0,0 +1,11 @@ +// PR c++/34238 +// { dg-do compile } + +namespace +{ + template struct A + { + static const bool a = true; + }; +} +struct A<> a; --- gcc/testsuite/g++.dg/ext/visibility/anon10.C.jj 2007-12-05 15:07:46.000000000 +0100 +++ gcc/testsuite/g++.dg/ext/visibility/anon10.C 2007-12-05 15:05:16.000000000 +0100 @@ -0,0 +1,44 @@ +// http://bugzilla.redhat.com/411871 +// { dg-do compile } + +extern "C" int printf (const char *, ...); + +struct E +{ + template E (const volatile T&); + template E (T&); + char x[64]; +}; + +template struct D +{ + static E foo (E, ...); + static int foo (T, int); +}; + +template struct C +{ + static T ca; + static const int value = sizeof (D::foo (ca, 0)) == sizeof (int); +}; + +struct A +{ + int a; +}; + +namespace +{ + struct B + { + int a; + }; +} + +int bar (void) +{ + C a; + C b; + + return a.value + b.value; +}