re PR c++/34238 ("static data member used, but not defined" error on member definition)

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.

From-SVN: r130771
This commit is contained in:
Jakub Jelinek 2007-12-11 09:22:10 +01:00 committed by Jakub Jelinek
parent 61a861e686
commit 5b767b9d0c
6 changed files with 65 additions and 16 deletions

View File

@ -1,5 +1,8 @@
2007-12-11 Jakub Jelinek <jakub@redhat.com>
PR c++/34238
* decl2.c (cp_write_global_declarations): Revert 2007-11-22 change.
PR c++/34364
* rtti.c (build_dynamic_cast): Call convert_from_reference even for
dynamic_cast in a template.

View File

@ -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),

View File

@ -1,5 +1,10 @@
2007-12-11 Jakub Jelinek <jakub@redhat.com>
PR c++/34238
* g++.dg/ext/visibility/anon7.C: Add xfail.
* g++.dg/ext/visibility/anon9.C: New test.
* g++.dg/ext/visibility/anon10.C: New test.
PR c++/34364
* g++.dg/rtti/dyncast2.C: New test.

View File

@ -0,0 +1,44 @@
// http://bugzilla.redhat.com/411871
// { dg-do compile }
extern "C" int printf (const char *, ...);
struct E
{
template <typename T> E (const volatile T&);
template <typename T> E (T&);
char x[64];
};
template<typename T> struct D
{
static E foo (E, ...);
static int foo (T, int);
};
template<typename T, typename U> struct C
{
static T ca;
static const int value = sizeof (D<U>::foo (ca, 0)) == sizeof (int);
};
struct A
{
int a;
};
namespace
{
struct B
{
int a;
};
}
int bar (void)
{
C<A, int> a;
C<B, int> b;
return a.value + b.value;
}

View File

@ -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;

View File

@ -0,0 +1,11 @@
// PR c++/34238
// { dg-do compile }
namespace
{
template <typename T = int> struct A
{
static const bool a = true;
};
}
struct A<> a;