PATCH for Bug in explicit template instantiation in presence of a static member (which is defined in terms of a nested templated class)
Mark Mitchell
mark@markmitchell.com
Sun May 24 18:56:00 GMT 1998
Here's a patch for your problem. Jason, OK?
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com
1998-05-24 Mark Mitchell <mark@markmitchell.com>
* pt.c (instantiate_decl): Handle static member variables
correctly.
Index: static2.C
===================================================================
RCS file: static2.C
diff -N static2.C
*** /dev/null Mon Dec 31 20:00:00 1979
--- static2.C Sun May 24 09:06:13 1998
***************
*** 0 ****
--- 1,21 ----
+ // Build don't link:
+
+ template <class A>
+ class TEST
+ {
+ public:
+ TEST (A) {}
+ };
+
+ template <class A>
+ class TEST2
+ {
+ static A i;
+ };
+
+ template <class A>
+ A TEST2 <A>::i (0);
+
+ TEST2 <TEST <int> > a;
+
+ template class TEST2 <TEST <int> >;
Index: pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.143
diff -c -p -r1.143 pt.c
*** pt.c 1998/05/23 02:18:31 1.143
--- pt.c 1998/05/24 16:26:35
*************** instantiate_decl (d)
*** 7082,7098 ****
lineno = DECL_SOURCE_LINE (d);
input_filename = DECL_SOURCE_FILE (d);
- /* We need to set up DECL_INITIAL regardless of pattern_defined if the
- variable is a static const initialized in the class body. */
- if (TREE_CODE (d) == VAR_DECL
- && ! DECL_INITIAL (d) && DECL_INITIAL (code_pattern))
- {
- pushclass (DECL_CONTEXT (d), 2);
- DECL_INITIAL (d) = tsubst_expr (DECL_INITIAL (code_pattern), args,
- tmpl);
- cp_finish_decl (d, DECL_INITIAL (d), NULL_TREE, 0, LOOKUP_NORMAL);
- }
-
if (pattern_defined)
{
repo_template_used (d);
--- 7093,7098 ----
*************** instantiate_decl (d)
*** 7124,7132 ****
goto out;
/* Defer all templates except inline functions used in another function. */
! if (! pattern_defined
! || (! (TREE_CODE (d) == FUNCTION_DECL && DECL_INLINE (d) && nested)
! && ! at_eof))
{
lineno = line;
input_filename = file;
--- 7124,7138 ----
goto out;
/* Defer all templates except inline functions used in another function. */
! if (/* We need to set up DECL_INITIAL regardless of
! pattern_defined if the variable is a static const
! initialized in the class body. */
! !(TREE_CODE (d) == VAR_DECL
! && DECL_INITIAL (d) == NULL_TREE
! && DECL_INITIAL (code_pattern) != NULL_TREE)
! && (! pattern_defined
! || (! (TREE_CODE (d) == FUNCTION_DECL && DECL_INLINE (d) && nested)
! && ! at_eof)))
{
lineno = line;
input_filename = file;
More information about the Gcc-bugs
mailing list