This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix a regression introduced by my PR34094 fix (PR c++/34238)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 26 Nov 2007 18:30:15 -0500
- Subject: [C++ PATCH] Fix a regression introduced by my PR34094 fix (PR c++/34238)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
As shown by the attached testcase (which is probably valid, as
A<>::a is never used and so it shouldn't be necessary to define
it), the DECL_INITIAL (decl) == NULL check doesn't work in cases
where it is actually never needed, only instantiated
(in that case tsubst_decl clears DECL_INITIAL:
/* We do NOT check for matching decls pushed separately at this
point, as they may not represent instantiations of this
template, and in any case are considered separate under the
discrete model. */
r = copy_decl (t);
DECL_USE_TEMPLATE (r) = 0;
TREE_TYPE (r) = type;
/* Clear out the mangled name and RTL for the instantiation. */
SET_DECL_ASSEMBLER_NAME (r, NULL_TREE);
SET_DECL_RTL (r, NULL_RTX);
DECL_INITIAL (r) = NULL_TREE;
DECL_CONTEXT (r) = ctx;
). The following patch fixes that. For the const static data members
with initializers in the class definition we won't issue any diagnostics,
but IMHO that's far less severe than making up the vars with default
initializer when there is none. I've also tried (attached patch)
instead delay this diagnostics after the vars have been output, so we
know for sure if it was emitted or not. That also fixes this anon9.C
and anon10.C gives diagnostics while it is without any diagnostics ATM,
but anon6.C breaks - there is the A<int>::c var actually emitted into
assembly, even when nobody really needs it :( (with or without the patch),
so with that alternate patch which checks TREE_ASM_WRITTEN we error on
anon6.C.
Is the first patch ok for trunk? Bootstrapped/regtested on x86_64-linux.
2007-11-26 Jakub Jelinek <jakub@redhat.com>
PR c++/34238
* decl2.c (cp_write_global_declarations): Test
!DECL_INITIALIZED_IN_CLASS_P instead of checking NULL
DECL_INITIAL.
* g++.dg/ext/visibility/anon9.C: New test.
--- gcc/cp/decl2.c.jj 2007-11-22 15:03:54.000000000 +0100
+++ gcc/cp/decl2.c 2007-11-26 21:04:38.000000000 +0100
@@ -3375,7 +3375,7 @@ cp_write_global_declarations (void)
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)
+ if (DECL_IN_AGGR_P (decl) && !DECL_INITIALIZED_IN_CLASS_P (decl))
error ("%Jstatic data member %qD used, but not defined",
decl, decl);
DECL_EXTERNAL (decl) = 0;
--- gcc/testsuite/g++.dg/ext/visibility/anon9.C.jj 2007-11-26 21:37:34.000000000 +0100
+++ gcc/testsuite/g++.dg/ext/visibility/anon9.C 2007-11-26 21:38:01.000000000 +0100
@@ -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;
Jakub