public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix a regression introduced by my PR34094 fix (PR c++/34238)
@ 2007-11-27  4:17 Jakub Jelinek
  2007-12-05 15:03 ` [C++ PATCH] Fix regressions introduced by my PR34094 fix (PR c++/34238, c++/34340) Jakub Jelinek
  0 siblings, 1 reply; 8+ messages in thread
From: Jakub Jelinek @ 2007-11-27  4:17 UTC (permalink / raw)
  To: Jason Merrill, Mark Mitchell; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-12-17 17:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-27  4:17 [C++ PATCH] Fix a regression introduced by my PR34094 fix (PR c++/34238) Jakub Jelinek
2007-12-05 15:03 ` [C++ PATCH] Fix regressions introduced by my PR34094 fix (PR c++/34238, c++/34340) Jakub Jelinek
2007-12-07  4:31   ` Mark Mitchell
2007-12-07  7:53     ` Jakub Jelinek
2007-12-07 20:52       ` Mark Mitchell
2007-12-10 13:19         ` Jakub Jelinek
2007-12-10 20:51           ` Mark Mitchell
2007-12-17 17:19           ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).