aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2001-01-08 14:41:03 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2001-01-08 14:41:03 +0000
commit3febd12318b0cdef645012bbce9cf85e4e4d80ed (patch)
tree6242c447972eef004491d7ec8e6c5786e021a632 /gcc
parentc7861455c823513906045e3214f7f8d7f44e2276 (diff)
downloadgcc-3febd12318b0cdef645012bbce9cf85e4e4d80ed.zip
gcc-3febd12318b0cdef645012bbce9cf85e4e4d80ed.tar.gz
gcc-3febd12318b0cdef645012bbce9cf85e4e4d80ed.tar.bz2
cp-tree.h (lang_decl_flags): Rename defined_in_class to initialized_in_class.
cp: * cp-tree.h (lang_decl_flags): Rename defined_in_class to initialized_in_class. (DECL_DEFINED_IN_CLASS_P): Rename to ... (DECL_INITIALIZED_IN_CLASS_P): ... here, to reflect true meaning. * decl.c (duplicate_decls): Preseve DECL_INITIALIZED_IN_CLASS_P. (cp_finish_decl): Adjust for DECL_INITIALIZED_IN_CLASS_P. * pt.c (check_default_tmpl_args): Adjust for DECL_INITIALIZED_IN_CLASS_P. (instantiate_class_template): Likewise. (instantiate_decl): Check DECL_INITIALIZED_IN_CLASS_P. * class.c (finish_struct): Constify saved_filename. testsuite: * g++.old_deja/g++.pt/instantiate12.C: New test. From-SVN: r38801
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog15
-rw-r--r--gcc/cp/class.c2
-rw-r--r--gcc/cp/cp-tree.h8
-rw-r--r--gcc/cp/decl.c4
-rw-r--r--gcc/cp/pt.c19
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C50
7 files changed, 85 insertions, 17 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 91d53af..088a279 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,20 @@
2001-01-08 Nathan Sidwell <nathan@codesourcery.com>
+ * cp-tree.h (lang_decl_flags): Rename defined_in_class to
+ initialized_in_class.
+ (DECL_DEFINED_IN_CLASS_P): Rename to ...
+ (DECL_INITIALIZED_IN_CLASS_P): ... here, to reflect true meaning.
+ * decl.c (duplicate_decls): Preseve DECL_INITIALIZED_IN_CLASS_P.
+ (cp_finish_decl): Adjust for DECL_INITIALIZED_IN_CLASS_P.
+ * pt.c (check_default_tmpl_args): Adjust for
+ DECL_INITIALIZED_IN_CLASS_P.
+ (instantiate_class_template): Likewise.
+ (instantiate_decl): Check DECL_INITIALIZED_IN_CLASS_P.
+
+ * class.c (finish_struct): Constify saved_filename.
+
+2001-01-08 Nathan Sidwell <nathan@codesourcery.com>
+
* class.c (duplicate_tag_error): Adjust diagnostic.
(finish_struct): Locally set location to start of struct.
* decl.c (fixup_anonymous_aggr): Use cp_error_at.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 08027ef..8b04aa3 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -5328,7 +5328,7 @@ tree
finish_struct (t, attributes)
tree t, attributes;
{
- char *saved_filename = input_filename;
+ const char *saved_filename = input_filename;
int saved_lineno = lineno;
/* Now that we've got all the field declarations, reverse everything
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 0da2283..e69a23a 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1812,7 +1812,7 @@ struct lang_decl_flags
unsigned declared_inline : 1;
unsigned not_really_extern : 1;
unsigned needs_final_overrider : 1;
- unsigned defined_in_class : 1;
+ unsigned initialized_in_class : 1;
unsigned pending_inline_p : 1;
unsigned global_ctor_p : 1;
@@ -2042,10 +2042,10 @@ struct lang_decl
should be allocated. */
#define DECL_IN_AGGR_P(NODE) (DECL_LANG_FLAG_3(NODE))
-/* Nonzero if the DECL was defined in the class definition itself,
+/* Nonzero if the DECL was initialized in the class definition itself,
rather than outside the class. */
-#define DECL_DEFINED_IN_CLASS_P(DECL) \
- (DECL_LANG_SPECIFIC (DECL)->decl_flags.defined_in_class)
+#define DECL_INITIALIZED_IN_CLASS_P(DECL) \
+ (DECL_LANG_SPECIFIC (DECL)->decl_flags.initialized_in_class)
/* Nonzero for FUNCTION_DECL means that this decl is just a
friend declaration, and should not be added to the list of
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 58fa5cd..33c0f80 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3573,6 +3573,8 @@ duplicate_decls (newdecl, olddecl)
DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
+ DECL_INITIALIZED_IN_CLASS_P (newdecl)
+ |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
olddecl_friend = DECL_FRIEND_P (olddecl);
/* Only functions have DECL_BEFRIENDING_CLASSES. */
@@ -7931,7 +7933,7 @@ cp_finish_decl (decl, init, asmspec_tree, flags)
&& CP_DECL_CONTEXT (decl) == current_class_type
&& TYPE_BEING_DEFINED (current_class_type)
&& (DECL_INITIAL (decl) || init))
- DECL_DEFINED_IN_CLASS_P (decl) = 1;
+ DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
if (TREE_CODE (decl) == VAR_DECL
&& DECL_CONTEXT (decl)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index ecf201a..5d4a1bf 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -1,6 +1,6 @@
/* Handle parameterized types (templates) for GNU C++.
- Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
- Free Software Foundation, Inc.
+ Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+ 2001 Free Software Foundation, Inc.
Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
Rewritten by Jason Merrill (jason@cygnus.com).
@@ -2300,7 +2300,7 @@ check_default_tmpl_args (decl, parms, is_primary, is_partial)
current_class_type)))
/* And, if it was a member function, it really was defined in
the scope of the class. */
- && (!DECL_FUNCTION_MEMBER_P (decl) || DECL_DEFINED_IN_CLASS_P (decl)))
+ && (!DECL_FUNCTION_MEMBER_P (decl) || DECL_INITIALIZED_IN_CLASS_P (decl)))
/* We already checked these parameters when the template was
declared, so there's no need to do it again now. This function
was defined in class scope, but we're processing it's body now
@@ -5059,7 +5059,7 @@ instantiate_class_template (type)
{
tree init;
- if (DECL_DEFINED_IN_CLASS_P (r))
+ if (DECL_INITIALIZED_IN_CLASS_P (r))
init = tsubst_expr (DECL_INITIAL (t), args,
/*complain=*/1, NULL_TREE);
else
@@ -5069,7 +5069,7 @@ instantiate_class_template (type)
/*asmspec_tree=*/NULL_TREE,
/*flags=*/0);
- if (DECL_DEFINED_IN_CLASS_P (r))
+ if (DECL_INITIALIZED_IN_CLASS_P (r))
check_static_variable_definition (r, TREE_TYPE (r));
}
@@ -9728,12 +9728,9 @@ instantiate_decl (d, defer_ok)
import_export_decl (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
- && TREE_READONLY (d)
- && DECL_INITIAL (d) == NULL_TREE
- && DECL_INITIAL (code_pattern) != NULL_TREE)
+ /* We need to set up DECL_INITIAL regardless, if
+ the variable is initialized in the class body. */
+ if (TREE_CODE (d) == VAR_DECL && DECL_INITIALIZED_IN_CLASS_P (d))
;
/* Reject all external templates except inline functions. */
else if (DECL_INTERFACE_KNOWN (d)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4be78f2..9940bd7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2001-01-08 Nathan Sidwell <nathan@codesourcery.com>
+ * g++.old_deja/g++.pt/instantiate12.C: New test.
+
+2001-01-08 Nathan Sidwell <nathan@codesourcery.com>
+
* g++.old-deja/g++.benjamin/15309-1.C: Expect diagnostic at
start of structs.
* g++.old-deja/g++.benjamin/15309-2.C: Likewise.
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C b/gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C
new file mode 100644
index 0000000..e1cc853
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.pt/instantiate12.C
@@ -0,0 +1,50 @@
+
+// Copyright (C) 2000 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 14 Nov 2000 <nathan@codesourcery.com>
+
+// Bug 635. We failed to emit initializer code for out-of-class defined
+// static const members of template instantiations.
+
+static int inited = 0;
+
+static bool setFlag()
+{
+ inited++;
+ return true;
+}
+
+template<typename T> struct X
+{
+ static const bool cflag;
+ static bool flag;
+ static const bool iflag = true;
+ static const bool jflag = true;
+};
+
+template<typename T> const bool X<T>::cflag (setFlag ());
+template<typename T> bool X<T>::flag (setFlag ());
+template<typename T> const bool X<T>::iflag;
+
+int main ()
+{
+ X<int> a;
+ if (!a.flag)
+ return 1;
+ if (!a.cflag)
+ return 2;
+ if (!a.iflag)
+ return 3;
+ if (!a.jflag)
+ return 5;
+ if (!X<float>::flag)
+ return 5;
+ if (!X<float>::cflag)
+ return 6;
+ if (!X<float>::iflag)
+ return 7;
+ if (!X<float>::jflag)
+ return 8;
+ if (inited != 4)
+ return 9;
+ return 0;
+}