From: jakub Date: Thu, 22 Nov 2007 14:06:06 +0000 (+0000) Subject: PR c++/34094 X-Git-Tag: upstream/4.9.2~44961 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=82aa7c7856f34f0b3d6d028c63f8ff6849e5ff62;p=platform%2Fupstream%2Flinaro-gcc.git PR c++/34094 * decl2.c (cp_write_global_declarations): Issue error about static data members in anonymous namespace which are declared and used, but not defined. * g++.dg/ext/visibility/anon7.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130351 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a8025f2..ae3cc02 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-11-22 Jakub Jelinek + + PR c++/34094 + * decl2.c (cp_write_global_declarations): Issue error about static + data members in anonymous namespace which are declared and used, + but not defined. + 2007-11-20 Jakub Jelinek PR c++/34089 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index d3ca117..bf3d598 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -3365,7 +3365,21 @@ 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)) - DECL_EXTERNAL (decl) = 0; + { + /* 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; + } } if (VEC_length (tree, pending_statics) != 0 && wrapup_global_declarations (VEC_address (tree, pending_statics), diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7380eb8..ccd81e9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-11-22 Jakub Jelinek + + PR c++/34094 + * g++.dg/ext/visibility/anon7.C: New test. + 2007-11-22 Tobias Burnus PR fortran/34079 diff --git a/gcc/testsuite/g++.dg/ext/visibility/anon7.C b/gcc/testsuite/g++.dg/ext/visibility/anon7.C new file mode 100644 index 0000000..23a915b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility/anon7.C @@ -0,0 +1,23 @@ +// PR c++/34094 +// { dg-do compile } + +namespace +{ + struct A { + static int bar (); + static int i; // { dg-error "used, but not defined" } + static int j; + static int k; + static int l; + static const int m = 16; + static const int n = 17; + }; + int A::j = 4; + int A::k; + const int A::m; +} + +int foo (void) +{ + return A::i + A::j + A::k + A::m + A::n + A::bar (); +}